3

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.

1 Answer 1

3

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

2
  • 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, 2012 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, 2012 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .