Using Hiera

See Getting Started with Hiera and in particular Using Hiera with Puppet.

  1. Install Hiera

    On the master:

    root@vhost1:~# apt-get install hiera

  2. Configure Hiera

    Still on the master, edit /etc/puppet.hiera.yaml:

    ---
    :backends:
      - yaml
    :logger: console
    :yaml:
       :datadir: /srv/puppet/common/hiera
    :hierarchy:
      - "%{environment}/%{calling_class}"
      - "%{environment}/defaults"
      - common
    	  

  3. Add some data

    In /srv/puppet/common/hiera/common.yaml, put:

    ---
    ntpserver: ntp0.xennet
    ntp::server: ntp0.xennet
    	  

  4. Use Hiera in a class

    E.g.

    file { '/tmp/hieratest':
      ensure => 'present',
      content => hiera('ntpserver'),
    }
    	  

  5. Test

    On the client:

    root@vhost2:~# puppet agent -t
    root@vhost2:~# cat /tmp/hieratest 
    ntp0.xennet

To test a yaml file locally:

root@vhost1:~# hiera -c /etc/puppet/hiera.yaml ntpserver
ntp0.xennet

[Warning]Warning

Hiera uses different default paths to hiera.yaml, depending on whether it starts standalone or as a child of Puppet.