Why do modules use classes in puppet (instead of defines)

puppet

Solution

I think the rationale behind this is best explained in John Arundel's Puppet 3 Beginner's Guide:

So if you're wondering which to use, consider:

- Will you need to have multiple instances of this on the same node (for example, a website)? If so, use a definition.

- Could this cause conflicts with other instances of the same thing on this node (for example, a web server)? If so, use a class.

Problem

I've been creating a couple of classes (in different modules) for puppet. Both, separately, require maven. So both classes have something like the following: ``` class { "maven::maven": version => "3.0.5" } ``` (using the https://forge.puppetlabs.com/maestrodev/maven module from puppet forge) But, if I have one node that has both of my classes, puppet complains because class 'maven::maven' is declared twice. I feel like each of my classes should be free to declare all of the things it needs. If a node has more than one class both of which require maven, then I don't see the problem. So, my question is: was the author of that maven module wrong to use a class, should he have used a define instead? (because you can use/call/whatever a define multiple times). It appears that if he had used a define I would be able to have the block of code as many times as I like, so if he was right to use a class, why? Thanks.

Original source