On Thursday, January 17, 2013 1:03:03 AM UTC-6, Boris
wrote:>
> I have a service resource in class ''foo'', and i want to
make a
> relationship with this resource from class ''bar''. Both
''foo'' and ''bar''
> classes are included in my node definition.
> From puppet docs i learned that dynamic scoping is still available for
> resources, but what happens in reality, is from-time-to-time error
"Could
> not find dependent Service".
>
> Can someone, please, help to explain this behavior?
>
Puppet resources never had dynamic scope. Instead, they have global scope *once
they are parsed*.
Wherever in your manifests you want to refer to a class or resource
declared elsewhere, it is essential to ensure that that external class or
resource has already been parsed. Provided that you are not using
parametrized classes, or that you do not declare your classes with explicit
parameter values, the best way to ensure a correct parse order is to
''include'' the class declaring (or constituting) the target
resource. So:
modules/mymodule/manifests/foo.pp:
------------------------------------------------------
class mymodule::foo {
service { ''foo_service'': }
}
modules/mymodule/manifests/bar.pp:
------------------------------------------------------
class mymodule::bar {
include ''mymodule::foo''
some_resource { ''bar_resource'':
require => Service[ ''foo_service'' ]
}
}
Note also that there is a growing sentiment that it is better style to
avoid cross-class relationships. Advocates of that style would instruct
you that instead of establishing a relationship directly with a resource
declared in a different class, you should establish the relationship with
the class that declares the resource. I am not yet fully persuaded, but
there are good arguments in support of that position. To following that
style rule, class bar would be written like this:
modules/mymodule/manifests/bar.pp:
------------------------------------------------------
class mymodule::bar {
include ''mymodule::foo''
some_resource { ''bar_resource'':
require => Class[ ''mymodule::foo'' ]
}
}
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/kKY0ty4Vo48J.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.