» Puppet Apply Provisioner

Provisioner name: puppet

The Vagrant Puppet provisioner allows you to provision the guest usingPuppet, specifically bycalling puppet apply, without a Puppet Master.

Warning: If you are not familiar with Puppet and Vagrant already,it is recommended to start with the shellprovisioner. However, if you are comfortable with Vagrant already, Vagrantis the best way to learn Puppet.

» Options

This section lists the complete set of available options for the Puppetprovisioner. More detailed examples of how to use the provisioner areavailable below this section.

  • binary_path (string) - Path on the guest to Puppet's bin/ directory.

  • facter (hash) - A hash of data to set as available facter variableswithin the Puppet run.

  • hiera_config_path (string) - Path to the Hiera configuration onthe host. Read the section below on how to use Hiera with Vagrant.

  • manifest_file (string) - The name of the manifest file that will serveas the entrypoint for the Puppet run. This manifest file is expected toexist in the configured manifests_path (see below). This defaultsto "default.pp"

  • manifests_path (string) - The path to the directory which contains themanifest files. This defaults to "manifests"

  • module_path (string or array of strings) - Path or paths, on the host, to the directory whichcontains Puppet modules, if any.

  • environment (string) - Name of the Puppet environment.

  • environment_path (string) - Path to the directory that contains environmentfiles on the host disk.

  • environment_variables (hash) - A hash of string key/value pairs to be set asenvironment variables before the puppet apply run.

  • options (array of strings) - Additionally options to pass to thePuppet executable when running Puppet.

  • synced_folder_type (string) - The type of synced folders to use whensharing the data required for the provisioner to work properly. By defaultthis will use the default synced folder type. For example, you can set thisto "nfs" to use NFS synced folders.

  • synced_folder_args (array) - Arguments that are passed to the folder sync.For example ['-a', '—delete', '—exclude=fixtures'] for the rsync synccommand.

  • temp_dir (string) - The directory where all the data associated withthe Puppet run (manifest files, modules, etc.) will be stored on theguest machine.

  • working_directory (string) - Path in the guest that will be the workingdirectory when Puppet is executed. This is usually only set because relativepaths are used in the Hiera configuration.

If only environment and environment_path are specified, it will parseand use the manifest specified in the environment.conf file. Ifmanifests_path and manifest_file is specified along with the environmentoptions, the manifest from the environment will be overridden by the specified manifest_file. If manifests_path and manifest_file are specified withoutenvironments, the old non-environment mode will be used (which will fail onPuppet 4+).

» Bare Minimum

The quickest way to get started with the Puppet provisioner is to justenable it:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet"
  3. end

puppet need to be installed in the guest vm.

By default, Vagrant will configure Puppet to look for manifests in the"manifests" folder relative to the project root, and will use the"default.pp" manifest as an entry-point. This means, if your directorytree looks like the one below, you can get started with Puppet withjust that one line in your Vagrantfile.

  1. $ tree
  2. .
  3. |-- Vagrantfile
  4. |-- manifests
  5. | |-- default.pp

» Custom Manifest Settings

Of course, you are able to put and name your manifests whatever you wouldlike. You can override both the directory where Puppet looks formanifests with manifests_path, and the manifest file used as theentry-point with manifest_file:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.manifests_path = "my_manifests"
  4. puppet.manifest_file = "default.pp"
  5. end
  6. end

The path can be relative or absolute. If it is relative, it is relativeto the project root.

You can also specify a manifests path that is on the remote machinealready, perhaps put in place by a shell provisioner. In this case, Vagrantwill not attempt to upload the manifests directory. To specify a remotemanifests path, use the following syntax:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.manifests_path = ["vm", "/path/to/manifests"]
  4. puppet.manifest_file = "default.pp"
  5. end
  6. end

It is a somewhat odd syntax, but the tuple (two-element array) saysthat the path is located in the "vm" at "/path/to/manifests".

» Environments

If you are using Puppet 4 or higher, you can provision usingPuppet Environments by specifying the name of the environment and the path on thelocal disk to the environment files:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.environment_path = "../puppet/environments"
  4. puppet.environment = "testenv"
  5. end
  6. end

The default manifest is the environment's manifests directory.If the environment has an environment.conf the manifest path is parsedfrom there. Relative paths are assumed to be relative to the directory ofthe environment. If the manifest setting in environment.conf usethe Puppet variables $codedir or $environment they are resolved tothe parent directory of environment_path and environment respectively.

» Modules

Vagrant also supports provisioning with Puppet modules.This is done by specifying a path to a modules folder where modules are located.The manifest file is still used as an entry-point.

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.module_path = "modules"
  4. end
  5. end

Just like the manifests path, the modules path is relative to the projectroot if a relative path is given.

» Custom Facts

Custom facts to be exposed by Factercan be specified as well:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.facter = {
  4. "vagrant" => "1"
  5. }
  6. end
  7. end

Now, the $vagrant variable in your Puppet manifests will equal "1".

» Configuring Hiera

Hiera configuration is also supported.hiera_config_path specifies the path to the Hiera configuration file stored onthe host. If the :datadir setting in the Hiera configuration file is arelative path, working_directory should be used to specify the directory inthe guest that path is relative to.

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.hiera_config_path = "hiera.yaml"
  4. puppet.working_directory = "/tmp/vagrant-puppet"
  5. end
  6. end

hiera_config_path can be relative or absolute. If it is relative, it isrelative to the project root. working_directory is an absolute path within theguest.

» Additional Options

Puppet supports a lot of command-line flags. Basically any setting canbe overridden on the command line. To give you the most power and flexibilitypossible with Puppet, Vagrant allows you to specify custom command lineflags to use:

  1. Vagrant.configure("2") do |config|
  2. config.vm.provision "puppet" do |puppet|
  3. puppet.options = "--verbose --debug"
  4. end
  5. end