Monday, September 30, 2013

Puppet: setting up hiera configuration in Vagrant

In Puppet, hiera configuration file is expected to be in /etc/puppetlabs/puppet/hiera.yaml.
How to automate the copy of this file, so that every time you do a "vagrant up" the whole Puppet environment is ready?
This is one way: in your Vagrantfile, BEFORE the " config.vm.provision :puppet do |puppet|" clause, you add this: config.vm.provision :shell, :inline => "ln -sf /vagrant/configuration/hiera.yaml /etc/puppetlabs/puppet/hiera.yaml"
and in your Vagrant folder on your host - under the folder containing the Vagrantfile - you create a folder "configuration", containing a hiera.yaml:
---
:backends: yaml
:yaml:
  :datadir: /vagrant/configuration/hieradata
:hierarchy: 
  - osb-vagrant-local
  - osb-vagrant
  

and a subfolder configuration/hieradata containing the files osb-vagrant.yaml and osb-vagrant-local.yaml (osb-vagrant is the hostname of my box as in config.vm.host_name = "osb-vagrant.acme.com"
Vagrant will "mirror" to /vagrant on the guest whatever is in your current folder on the host. The symbolic link will do the rest.
At this point you can enter any variable in osb-vagrant.yaml, like
pippo : pluto
and if you do hiera('pippo) you should get pluto.



No comments: