On Wed, Dec 07, 2011 at 01:36:13PM -0800, jcbollinger wrote: > On Dec 6, 4:12 pm, "Christian G. Warden" <cwar...@xerus.org> wrote: > > On Tue, Dec 06, 2011 at 01:38:38PM -0800, Nan Liu wrote: > > > On Tue, Dec 6, 2011 at 12:27 PM, Christian G. Warden <cwar...@xerus.org> > > > wrote: > > > > Do explicit class dependencies work? [...] > > Here's the problem I was actually trying to > > troubleshoot: > > class config { > > $x = 'abc' > > } > > > > class uses_config { > > Class['config'] -> Class['uses_config'] > > $x = $config::x > > } > > > > include uses_config > > include config > > > > This results in: > > warning: Scope(Class[Uses_config]): Could not look up qualified variable > > 'config::x'; class config has not been evaluated > > > > I think it's similar to the problem I asked about with tags in another > > thread. > > If I include config before uses_config, I don't get an error. > > Indeed, it is at least partially a parse order issue, and it looks > like you may be confusing that with application order.
Thanks, John. This explanation is very helpful. Indeed, I've been having trouble understanding what happens during the parsing/compiling stage. > Class and resource relationships, such as those declared via the arrow > syntax in your example or via the 'require' family of resource > metaparameters, govern the order in which resources are applied to > nodes. That has very little to do with the order in which manifest > files are processed by Puppet. The relationship you declare in your > example does not cause class 'config' to be included on the node, nor > its manifest to be parsed. It only specifies that class 'config' must > be applied to the node before class 'uses_config', which is pointless > in this simplified example. Class 'uses_config' needs class 'config' > to already have been parsed, however, and you example does nothing to > make that so. At least part of my confusion is the use of imprecise language in the documentation. For example, this example from the language guide's section on qualified variables[1]: class myclass { $test = 'content' } class anotherclass { $other = $myclass::test } "Variable qualification is dependent on the *evaluation order* of your classes. Class myclass must be evaluated before class anotherclass for variables to be set correctly." (emphasis added) The term, evaluation order, is not used anywhere else in the language guide. Does it refer to parsing, compiling, instantiation, or configuration, to use the terms from the puppet internals[2] documentation? > For influencing parse order you have three functions: 'import' (which > you shouldn't use except in certain special cases such as site.pp), > 'include', and 'require'. The 'import' function processes one or more > manifest files explicitly. The 'include' and 'require' functions both > assign the specified class to the current node, autoloading and > processing its manifest first, if necessary. The 'require' function > additionally establishes a relationship between the requiring class > and the required one, of just the type that your example creates via > the arrow syntax; in other words, it declares both types of > dependencies in a simple statement. The parameterized classes documentation[3] is also confusing. It states that "you should explicitly state your class's dependencies inside its definition using the relationship chaining syntax" and explicitly declare your required parameterized classes "in your outermost node or class definitions", which is what I tried to do in my example. > Generally speaking, if one class references variables of another class > then the first class should 'include' the second, or posibly 'require' > it if that's appropriate. If it cannot do so (because the latter > class is parameterized, for instance) then you have an extra burden to > ensure that classes are declared and/or 'include'd in an order that > works. This statement from the parameterized classes documentation[3] obscures the limitation in the language you identify above: "For those who prefer implicit declaration, we're working on a safe way to implicitly declare parameterized classes, but the design work isn't finished at the time of this writing." It suggests that it is only an aesthetic issue, but it really means that there is currently no way of declaring a parameterized class multiple times like you can (implicitly) do with 'include'. The style guide explicitly discourages having one class declare another[4]: "*Classes should generally not declare other classes.*" (emphasis in original) And the language guide says order doesn't matter[1]: "Puppet language is a declarative language, which means that its scoping and assignment rules are somewhat different than a normal imperative language. ... Order does not matter in a declarative language." I hope this doesn't come off as too much of a rant. I'm a big fan of puppet (even more so in the past couple weeks as I've started using it with vagrant), but there's definitely room for improvement in the documentation. Perhaps the puppet glossary[5] should be featured on the documentation section of puppetlabs.com, and existing documentation should be reviewed for consistency with the glossary. Christian 1. http://docs.puppetlabs.com/guides/language_guide.html#variables 2. http://docs.puppetlabs.com/guides/puppet_internals.html 3. http://docs.puppetlabs.com/guides/parameterized_classes.html#site-design-and-composition-with-parameterized-classes 4. http://docs.puppetlabs.com/guides/style_guide.html#general-philosophies 5. http://projects.puppetlabs.com/projects/1/wiki/Glossary_Of_Terms -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.