Create an environment

Create an environment by adding a new directory of configuration data.

  1. Inside your code directory, create a directory called environments.
  2. Inside the environments directory, create a directory with the same name as your new environment.
  3. Inside that directory, create a modules directory and a manifests directory. These two directories contain your Puppet code.
  4. Configure a modulepath:
    1. Set modulepath in its environment.conf file . If you set a value for this setting, the global modulepath setting from puppet.conf is not used by an environment.
    2. Check the modulepath by specifying the environment when requesting the setting value:

    $ sudo puppet config print modulepath --section server --environment test /etc/puppetlabs/code/environments/test/modules:/etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules.
    In Puppet Enterprise (PE), every environment must include /opt/puppetlabs/puppet/modules in its modulepath, because PE uses modules in that directory to configure its own infrastructure.

  5. Configure a main manifest:
    1. Set manifest in its environment.conf file. As with the global default_manifest setting, you can specify a relative path (to be resolved within the environment’s directory) or an absolute path.
    2. Lock all environments to a single global manifest with the disable_per_environment_manifest setting — preventing any environment setting its own main manifest.
  6. To specify an executable script that determines an environment’s config version:
    1. Specify a path to the script in the config_version setting in its environment.conf file. Puppet runs this script when compiling a catalog for a node in the environment, and uses its output as the config version. If you specify a value here, the global config_version setting from puppet.conf is not used by an environment.

    If you’re using a system binary like git rev-parse, specify the absolute path to it. If config_version is set to a relative path, Puppet looks for the binary in the environment, not in the system’s PATH.

Results

Example environment.conf file:

# /etc/puppetlabs/code/environments/test/environment.conf

# Puppet Enterprise requires $basemodulepath; see note below under "modulepath".
modulepath = site:dist:modules:$basemodulepath

# Use our custom script to get a git commit for the current state of the code:
config_version = get_environment_commit.sh

Related topics: Deploying environments with r10k, Code Manager control repositories, disable_per_environment_manifest