This frees you to use different versions of the same modules for different populations of nodes, which is useful for testing changes to your Puppet code before implementing them on production machines. (You could also do this by running a separate Puppet master for testing, but using environments is often easier.)
There are two ways to set up environments on a Puppet master: directory environments, and config file environments. Note that these are mutually exclusive — enabling one will completely disable the other.
Directory environments are easier to use and will eventually replace config file environments completely.
You can assign agent nodes to environments using either the agent’s config file or an external node classifier (ENC).
For details, see the page on assigning nodes to environments.
In Puppet manifests, you can get the name of the current environment by using the
$environment variable, which is set by the Puppet master.
Directory environments let you add a new environment by simply adding a new directory of config data. Here’s what you’ll need to know to start using them:
Since directory environments are a major change to how Puppet loads code and serves configurations, they aren’t enabled by default yet. (They will become the only way to manage environments in Puppet 4.0.)
To start using directory environments, do the following:
If a node is assigned to an environment which doesn’t exist — that is, there is no directory of that name in any of the
environmentpath directories — the Puppet master will fail compilation of its catalog.
If directory environments are enabled, they will completely disable config file environments. This means:
config_versionsettings in puppet.conf.
To use config file environments, see the reference page on config file environments.
This section of the Puppet reference manual has several other pages about environments: