Placement of Variables in Puppet module

puppet

I've got a puppet module to setup several Gigaspaces PU's. Each of these have quite a few variables to be placed within the configuration file templates. We're also using several different environments so these variables are repeated several times to contain the values for each environment.

My question is where the best place to store these variables would be? A class of their own, an external .pp I import, or something other?

Best Answer

A lot of what you're asking comes down to convention more than strict language requirements... The language is flexible enough to do things a number of different ways.

If all the servers are being configured the same, it should work fine to have a single "gigaspace" class with the variables set at the top.

If your needs are more complicated than a single class of server, what I would do is create a "gigaspace" module with a common class holding variables inherited by classes needing the variables. In gigaspace/manifests there'd be an "init.pp" containing "class gigaspace {...}", and then a "common.pp" containing "class gigaspace::common {...}". Then in any class that I needed access to those variables, I would inherit from the common class, like "class gigaspace::master inherits gigaspace::common { ... }".

If you don't inherit from the other class, it's a pain to get at variables in another class, especially from within a template. With a straight include you can get read-only access via specifying the whole name, however.

Related Topic