Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a situation in puppet where I want to inherit from a parametrized class:

class base ($basepath) {
  ...
}

class extends_base ($ext_param) inherits base {
  ...
}

Now trying to instantiate the extends_base class I get the following error message:

Must pass basepath to Class[Base]

However, I don't see a way how to pass the basepath parameter to the Base class.. I tried to pass the param in the Class[Extends_base] definition, puppet doesn't like this either.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Puppet does not support inheritance with parameterized base classes, i.e. the base class must not be parameterized for inheritance to work. So what you are trying to do is currently not possible.

See here for details: http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html#inheritance

share|improve this answer
    
that's a pitty. Looks like the inheritance concept in puppet doesn't really match with the rest, it seems to be added on top of the existing concepts without adapting to it. –  paweloque Oct 30 '12 at 16:47
2  
Puppet's inheritance model doesn't have much in common with inheritance as we know it from object oriented languages. This often leads to surprises when people try to employ it, like in your case. Best to avoid it wholly, as it isn't even that useful in the first place. And now that Hiera is fully integrated in Puppet, the "parameterized class" pattern (the IMHO only useful application of Puppet inheritance, where the main class inherits a params class) can be happily retired. –  daff Oct 30 '12 at 20:32
    
thanks for your detailed explanation! –  paweloque Oct 31 '12 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.