What is the major differences between Puppet inheritance vs Puppet composition.?
What is the major differences between Puppet inheritance vs Puppet composition.?
I just came cross puppet inheritance lately. A few questions around it:
1. Is it a good practice to use puppet inheritance? I've been told by some of the experienced puppet colleagues Inheritance in puppet is not very good, I was not quite convinced.
2. Coming from OO world, I really want to understand under the cover, how puppet inheritance works, how overriding works as well.
emmablisa
Posted 9 years ago·Last reply 9 years ago
1 comment
eculler
·9 years agoHi emmablisa,
Thanks for your questions. There are a few differences between inheritance and composition which lend themselves to slightly different use cases. Currently in our environment we use a combination of both class inheritance and composition to try and get the most out of each.
Inheritance:
There are 2 kinds of inheritance in (certain versions) of puppet. Node and class inheritance. As of puppet 4.0.0 node inheritance has been removed from the puppet language, so I'm going to skip that one.
Class inheritance has the following effects
In addition to the usage in modules like this, we use inheritance to reduce the redundancy of code in the role/profile framework documented here.
Composition:
This is a way to establish a ordering relationship while avoiding duplicate declaration of resources.
If 2 classes within a profile have a dependency on the same class you can run into duplicate resource declaration errors.
Hopefully this answers your questions.
~Ethan