Actions: | Security

Navigation: Home | Services | Tools | Articles | Other

Specifying a Puppet Environment at the Puppetmaster

Specifying a Puppet Environment at the Puppetmaster

Puppet environments are a powerful feature that facilitate categorising systems, based on status (such as production, testing, development, etc.) or some other criteria, such as location, responsibility, etc. etc.

Basically the idea is to specify an environment and the puppetmaster provides a different catalog based off different manifests (or different modules or different parameters or all of the above)

On the puppetmaster

Insert into the [master] section of the server's puppet.conf something like this:

   manifest    = $confdir/environments/$environment/manifests/site.pp
   modulepath  = $confdir/environments/$environment/modules

This means that you can start building environments under /etc/puppet/environments. They should look just like the ordinary puppet repository, with directories for manifests and modules.

On the puppet clients

Specify the environment either in the [agent] section of the client's puppet.conf or, if running puppet from the command line, by passing --environment=foo.

Specifying which environment a node should use

I make a special environment, bootstrap, which is used when I need to bootstrap puppet. Its entire purpose is to configure the client's puppet so all it contains is a site manifest and a puppet module.

$environments/bootstrap/manifests/site.pp specifies which environment a given node should get. Currently, it is by hostname (or hostname regex):

node default {
    include puppet
node production inherits default {
node dev {
    class {'puppet':
        my_environment => 'dev'
node /.*$/ inherits dev {}
node "" inherits dev {}

Then there is a very simple module that defines a class that manages the puppet.conf, the puppet package and the puppet service.

Selecting environments with the bootstrap environment

This means I can easily move a machine from one environment to another.

A puppet agent can have its environment set in the configuration file /etc/puppet/puppet.conf or with the argument --environment.

Therefore, there are 2 simple steps to reinitialize the environment for a host.