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?
> > > This simple example fails with:
> > > Could not find resource 'Class[Config]' for relationship on 
> > > 'Class[Uses_config]'
>
> > > class config {
> > > }
>
> > > class uses_config {
> > > Class['config'] -> Class['uses_config']
> > > }
>
> > > include uses_config
>
> > > Am I doing something?
>
> > You didn't declare include class config. If you intend uses_config to
> > automatically include class config, you should declare it there. In
> > either case you are missing include config or class { config: }
> > somewhere.
>
> Thanks, Nan.  Sorry, I got a little overzealous in trying to come up
> with a minimal example.  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.

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.

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.

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.


John

-- 
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.

Reply via email to