Is the accepted alternative to inheritance of the doll node class inclusion?

After reading a few style guides and trying not to use inheritance in my node definitions ( as suggested by puppet labs ), I would like to know what is the general way of including classes in a puppet without using inheritance.

I'm trying to do the following with my node definitions, but it doesn't work:

# in module 'baseclass'
# baseclass.pp
class baseclass {
  include xclass
  include yclass
  include zclass
}

# servernode01.pp
node 'servernode01' {
  include baseclass
} 

      

where xclass

, yclass

and zclass

are functional puppet classes, including them in node servernode01

yields the desired state (i.e. resources are applied to the node).

My question (s):

  • Does classes include in classes a good alternative to inheritance?
  • Are there any problems with the methodology I am using as an alternative to inheritance?

I am asking my second question since it seems that the nodes that include baseclass

are not getting the resources defined in xclass

, yclass

and zclass

.

My ultimate goal is to have a base class that will fulfill the minimum requirements that I will specify.

+3


source to share


2 answers


  • yes composition is better than inheritance in Puppet
  • your example should work fine


The alternative include baseclass

is class { 'baseclass': }

. You need the latter if you want to use parameters, and also consider that you can use include

multiple times, but not the syntax class

, as the puppet will complain about defining a repeating class.

+3


source


Official puppet documents clearly state that inheritance should only be used "sparingly" in reality. In fact, they will name exactly two situations when this should happen:

  • when you want to overwrite the parameter of a resource defined in the parent class
  • if you want to inherit from parameter class for standard parameter values


see http://bit.ly/1r1RO0K

So yes, this is clearly better, even with an official blessing :)

+2


source







All Articles