Code and data directory (codedir)

The codedir is the main directory for Puppet code and data. It is used by Puppet master and Puppet apply, but not by Puppet agent. It contains environments (which contain your manifests and modules), a global modules directory for all environments, and your Hiera data and configuration.

Location

The codedir is located in one of the following locations:
  • *nix: /etc/puppetlabs/code

  • *nix non-root users: ~/.puppetlabs/etc/code

  • Windows: %PROGRAMDATA%\PuppetLabs\code (usually C:\ProgramData\PuppetLabs\code)

When Puppet is running as root, a Windows user with administrator privileges, or the puppet user, it uses a system-wide codedir. When running as a non-root user, it uses a codedir in that user's home directory.

When running Puppet commands and services as root or puppet, you should usually use the system codedir. To use the same codedir as the Puppet agent, or Puppet master, run admin commands such as puppet module with sudo.

Note: Running the master as a Rack application is deprecated. When Puppet master is running as a Rack application, the config.ru file must explicitly set --codedir to the system codedir. The example config.ru file provided with the Puppet source does this.
To configure the location of the codedir, set the codedir setting in your puppet.conf file, such as:
codedir = /etc/puppetlabs/code
Important: Puppet Server doesn't use the codedir setting in puppet.conf, and instead uses the jruby-puppet.master-code-dir setting in puppetserver.conf. When using a non-default codedir, you must change both settings.

Interpolation of $codedir

The value of the codedir is discovered before other settings, so you can refer to it in other puppet.conf settings by using the $codedir variable in the value. For example, the $codedir variable is used as part of the value for the environmentpath setting:
[master]
   environmentpath = $codedir/override_environments:$codedir/environments

This allows you to avoid absolute paths in your settings and keep your Puppet-related files together.

Contents

The codedir contains environments, including manifests and modules, a global modules directory for all environments, Hiera data, and Hiera's configuration file, hiera.yaml.

The code and data directories are:
  • environments: Contains alternate versions of the modules and manifests directories, to enable code changes to be tested on smaller sets of nodes before entering production.
  • modules: The main directory for modules.