On Monday, October 15, 2012 4:27:06 AM UTC-5, Simon Marechal wrote:
>
> It seems to me that a few puppet modules do access variables from 
> non-included classes (for example 
> https://github.com/puppetlabs/puppetlabs-mysql/blob/master/manifests/config.pp
>  look 
> at how stuff is pulled out of mysql::params).
>
>
That example works because the class inherits from mysql::params.  It is a 
pattern that has come into vogue for making another class's variables 
accessible for use as class parameter defaults.  Included classes' 
superclasses are automatically included, much as if the superclass were 
'include'd just prior to each declaration of the subclass (whether via 
parametrized syntax, 'include', or 'require').

 

> I do not understand how this is supposed to work. What happens if you do 
> this from a parameterized class, and include it later with distinct 
> parameters ?
>


What's "this"?  Are you asking about what happens if the superclass is 
itself parametrized?  That is not supported.

If you happen to do it anyway, however, the result is similar to what would 
happen if you 'include'd the superclass instead of inheriting from it -- as 
long as the parametrized declaration is parsed first, everything will 
compile and the class will have the parameters from the parametrized-form 
declaration.  If the parametrized declaration is parsed second, however, 
then catalog compilation will fail.  I advise you to avoid all that, and 
instead just don't inherit from parametrized classes.

In fact, in a reprise of my "voice crying in the wilderness" routine, I 
will urge you to avoid writing new parametrized classes for any context or 
purpose.  Puppet 3's integration of hiera with class parameter resolution 
provides a nice backstop for people who invested in developing parametrized 
classes, but parametrized classes still have serious deficiencies in Puppet 
3 (and worse deficiencies in Puppet 2).  Do write them.  If you need to use 
parametrized classes written by someone else, then at all costs avoid 
parametrized class declaration syntax; instead use the good old 'include' 
function (or the 'require' function).  Feed non-default parameter data to 
them via hiera (requires Puppet 3).

 

> Is that even legal ? What about resources that might be in mysql::params ? 
> Or is that just working because of the inheritance ?
>
 

Any resources declared in class mysql::params are assigned to nodes that 
declare any of its subclasses.  That's an aspect of Puppet class 
inheritance.


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