How to set up :datadir: when using Hiera with Puppet and Vagrant

Solution 1:

I found the solution while documenting my question. Change :datadir: to read:

  :datadir: "%{settings::manifestdir}/configuration"

Puppet will provide the path to the manifest directory in $settings::manifestdir. Storing the Hiera data inside the manifest directory is useful because Vagrant will mount this directory explicitly before running Puppet in the guest system, and other directories you might select for this purpose might not be available.

Solution 2:

The hiera.yaml I'm working with specifies :datadir: /etc/puppet/hiera and I had no luck with setting the --yamldir option as some of the other answers specified. However, I realised after a while that I could just map my hieradata to that location on the guest vm:

config.vm.synced_folder "../puppet/hiera", "/etc/puppet/hiera"

This works nicely :-)

Solution 3:

This is what I am doing in my own puppet experiments.

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "puppetlabs/debian-7.8-64-puppet" # source box on atlas
  config.vm.hostname = "wheezybox"                  # hostname of box

  # Include Hiera Data Directory (no automatic option for this)
  config.vm.synced_folder "../../hieradata", "/tmp/vagrant-puppet/hieradata"

  # Puppet Configuration
  config.vm.provision :puppet do |puppet|
    puppet.manifests_path    = "../../manifests/"
    puppet.manifest_file     = "site.pp"
    puppet.module_path       = ["../../modules/"]    # shared modules
    puppet.hiera_config_path = "../../hiera.yaml"    # hiera config file
    puppet.working_directory = "/tmp/vagrant-puppet" # default hiera path
    puppet.options           = "--verbose --debug"
  end
end

My minimalist hiera.yaml looks like this:

---
:backends:
  - yaml
:yaml:
  :datadir: "hieradata"
:hierarchy:
  - "node/%{::hostname}"

And for illustration purposes, my directory structure on the host (MacBook) looks like this:

    .
    ├── hiera.yaml
    ├── hieradata
    │   └── node
    │       ├── centos6box.yaml
    │       ├── precisebox.yaml
    │       └── wheezybox.yaml
    ├── manifests
    │   └── site.pp
    ├── modules -> ../puppet-common/modules/
    └── vagrants
        ├── README.md
        ├── centos6
        │   └── Vagrantfile
        ├── precise
        │   └── Vagrantfile
        └── wheezy
            └── Vagrantfile