Charlie Sharpsteen and I came across this from Chris Spence while triaging bugs today: https://projects.puppetlabs.com/issues/18109
This helps to clarify that resource-style class declarations and 'include' work the same with regard to namespacing. If you folks know of other bugs that seem similar can you please link them up to this one with the "Related issues" field in redmine, or just reply to this thread? I have a hunch that there's at a minimum some documentation that needs to be punched up around this, and possibly behavioural change since it seems counter to a lot of people's expectations. Thanks! Eric Sorenson - [email protected] irc.freenode.net #puppet: eric0 On Feb 26, 2013, at 11:34 PM, Keith Burdis wrote: > I have run into similar scoping issues in the past so I often use: > > include ::myclass > > to avoid "relative" class lookups. > > - Keith > > On 27 Feb 2013 02:30, "James Polley" <[email protected]> wrote: > > > On Tuesday, 26 February 2013 00:47:29 UTC+11, llowder wrote: > > > On Sunday, February 24, 2013 10:27:13 PM UTC-6, James Polley wrote: > We're using ::params classes quite extensively to share values across all > classes in a module: > > class myclass ( > $param1 = $myclass::params::param1 > ) inherits myclass::params { > ... code ... > } > > class myclass::subclass ( > $param1 = $myclass::params::param1 > ) inherits myclass::params { > ... code ... > } > > define myclass::definetype ( > $param2 = 'value2' > ) { > include myclass::params > myvalue = $myclass::params::param1 > } > > class myclass::params () { > $param1 = 'value' > } > > The goal is that these values can be set in one place and get used everywhere > throughout the module. > > This works just for for classes inside the module, because the 'inherits' > forces the ::params class to be processed first. > > However, we consistently run into issues using define types from the module - > we can't figure out how to guarantee that the ::params class gets loaded > before the define types. > > (Scope(Myclass::Definetype[resourcename])) Could not look up qualified > variable 'myclass::params::param1'; class myclass::params has not been > evaluated > > I'm hoping there's something fairly simple I'm forgetting about that we can > use to force the class to be evaluated before any instance of the types. > > First off, defines are not classes and cannot be treated as such. > > I'm not sure what you're referring to here. > > Defines act more like the built in resources - user, file, package etc. > > If you need to make sure that your params class gets processed before the > defines, you can safely "include myclass::params" in it. > > Tried that; tried using "require" instead of "include". Tried > including/requiring in the class where the define is instantiated; tried > using the require metaparameter to set up relationships; we still end up > getting told that "class myclass::params has not been evaluated". > > But we think we've figured this out. > > myclass::definetype was being called from inside > anothermodule::roles::aclass. anothermodule also includes a class called > anothermodule::roles::myclass - and it seems that include myclass was causing > anothermodule::roles::myclass to be evaluated rather than myclass > > Removing anothermodule::roles::myclass (it was dead code and should have been > gone already) fixed the problem. > > You may also want to look at NOT using inheritance at all for that, and > instead using "include". You can pair that with the anchor pattern or > "anchor-lite" to ensure ordering. > > You may also find this article to be quite helpful. It has a good pattern, > and also shows "anchor lite". > http://www.devco.net/archives/2012/12/13/simple-puppet-module-structure-redux.php > > That doesn't quite seem relevant to this situation, but it *is* a good read. > Thanks for the link! > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/puppet-dev?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/puppet-dev?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-dev?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
