I wrote puppet manifests and I use puppet to deploy my system. I am now refactoring manifests in order to make it maintainable.
One of sub systems is tomcat with webapplications. I have ~10 webapps. Each of those has almost the same procedure to deploy. For now I use classes. 10 files - almost identical.
When I tried to use parametrized class, puppet lets me instantiate it just once. Then I tried to create 'empty' classes which inherit from webapp class. It does not work as well because puppet complains that parameters are not passed parent class.
I do not see any method I could abstract the code. How to do it?
I would like to achieve:
node {
class {"webapp::first": param1 = one}
class {"weba开发者_如何学Cpp::second": param1 = two}
}
where first and second are applications using the same recipes.
I know there is define, but recipe is pretty big and even if it would be possible I find class more readable.
You can use parameters in your classes, but defines are more what you want. Quoting the official documentation
Classes and defined types are created similarly, but they are used very differently.
Defined types are used to define reusable objects which will have multiple instances on a given host, so > they cannot include any resources that will only have one instance. For instance, multiple uses of the > same define cannot create the same file.
see http://docs.puppetlabs.com/guides/language_guide.html#resource-collections
try to use user defined type classes are singleton by nature
精彩评论