On Thursday, August 27, 2015 at 7:59:28 AM UTC-5, Peter Huene wrote:
On Wed, Aug 26, 2015 at 11:50 PM, Francis Chan
<poi...@gmail.com> wrote:
I'm using the something like this since I want all of class bar to be applied before any class foo:
# init.pp for module bar
class bar( $var = "hello" )
{
}
# something.pp in module foo
class foo::something {
require bar
}
Instead of using the `require` function, try using the "resource-like" declaration syntax:
Oh, goodness No! Avoid resource-like class declarations wherever possible, and
always avoid using them to declare public classes of any module. Although resource-like syntax does provide for specifying parameters at the point of declaration, it introduces both an evaluation-order dependency and a potential declaration conflict.
The best way to provide class parameter values, especially for public classes, is via Puppet's automatic data binding feature. If you're using an ENC, then providing class parameters via ENC is also a reasonable alternative. The manual
discusses class declarations and the include-like (which includes 'require') vs. resource-like styles. Do not overlook the best-practices callout in that section. There are cases where using resource-like syntax makes sense, but simply wanting to provide non-default parameter values is in no way good justification.
Automated data binding relies on Hiera. A full run-down on Hiera use is a little out of scope here, but basically, when you declare any class, using either style, Puppet will perform a Hiera lookup for each class parameter that is not assigned a value in the declaration (for include-like syntax, that's all of them). It uses keys of the form "full::class::name::parameter", and if that key is present then its value is used as the value for the class parameter. In your example, then, you would arrange for Hiera to provide a value for key "bar::var".
John