On Friday, January 11, 2013 12:01:52 PM UTC-6, Erik Dalén wrote: > > At least in puppet 3 resource defaults are local to defines and classes > and doesn't get inherited to any included defines or classes. So to make > upgrading easier you shouldn't make any such assumptions in your code. >
That is not correct (see http://docs.puppetlabs.com/puppet/3/reference/lang_defaults.html). The problem is that resource defaults are dynamically scoped (even in Puppet 3), not lexically scoped. Roughly speaking, that means defaults follow the chain of declarations, regardless of the location of the definitions of the classes and definitions in the chain. Thus, if the OP's original code declared a File resource directly in class nginx::config, then File defaults declared in that class would apply to it. If it declared an nginx::config::extra instance directly in class nginx::config, then the File defaults of nginx::config and of nginx::config extra would apply to it. But if an instance of nginx::config::extra is declared by class mymodule::foo, then the File defaults that apply to that instance are those that apply in mymodule::foo, as modified by the default declarations appearing directly in nginx::config::extra. Moving the File defaults declaration from nginx::config into the definition is a perfectly valid way to achieve the desired result. Dynamic scoping of resource defaults can indeed produce surprises, but assuming local scope for defaults is not the solution (that incorrect assumption could also produce surprises). There would, however, be less likelihood of confusion in the present case if the definition were not nested inside a class. PuppetLabs style recommendations include to avoid nesting classes or definitions inside classes, and I am convinced that following that recommendation yields better code. 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/-/OZlLgLG_EW0J. 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.