5
votes

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.

2

2 Answers

8
votes

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.
0
votes

If you're passing in parameters to a class, there is a possibility of a conflict, the problem being that it is not clear which sets of parameters will get used.

If your first module required maven with 3.0.5 but your second module required maven with 3.0.6, puppet would not know which one to use.

The puppet module, in making it a class and not a resource/defined type, does not handle the resolution as well, because it was probably intended for a single install.

Puppet currently only supports re-using class declarations without parameters, ie. include maven::maven.

Finally, declaring dependencies on other modules in your own module is a tricky thing, that I do not know how to fully resolve yet.