Daniel Pittman <dan...@rimspace.net> writes:

> It was, until yesterday, my naive expectation that this would work:

> node default                    { include broken }
> node "krosp" inherits "default" { $value = "not " }
> class broken                    { notice("This is ${value}broken") }

> Specifically, I expected this would output 'This is not broken', but instead
> we get the counter-intuitive and *very* annoying 'This is broken'.

> As far as I can tell this is because puppet treats $value as out of scope to
> the classes included from default: the order of processing is:

>  - node 'default', or any other inherited node.
>    - any classes included are processed.
>  - node $hostname is processed.

> This means our practice of included universal features into the default
> node, then inheriting that into other nodes, also makes it impossible
> for us to do things like configure features of those universal classes.

> I really do *NOT* want to go down the path of having to repeat the same
> set of classes in every node; that invites disaster, by forcing me to
> repeat myself.

Our rule of thumb is that any time one is tempted to set variables and use
those values in included and inherited classes, that's a red flag that you
actually wanted a define instead.  If you had instead written this as:

node default { broken { "message": value => "" } }
node "krosp" inherits "default" { Broken["message"] { value => "not " } }
define broken($value) { notice("This is ${value}broken") }

I'm pretty sure you'd get the behavior you expected.

-- 
Russ Allbery (r...@stanford.edu)             <http://www.eyrie.org/~eagle/>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-us...@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