Saturday, August 31, 2013

Puppet: getting started with hiera (hiera example)

Official doc here

I don't like hiera, but it's better than hardcoding configuration in .pp files.
First attempt:
vi hieratest.pp
$pippo = hiera('pippo')
notify { "${pippo}" : }

I run "puppet apply hieratest.pp" and I get:
Hiera config file /etc/puppetlabs/puppet/hiera.yaml not readable at /root/puppettests/hieratest.pp:1
then I do vi /etc/puppetlabs/puppet/hiera.yaml and I enter:
:hierarchy:
    - hosts/%{::fqdn}
    - environments/%{environment}
    - common
    - users

:backends:
    - yaml

:yaml:
    :datadir: '/etc/puppetlabs/puppet/hieradata/'


and rerun "puppet apply hieratest.pp" and I get:
Could not find data item pippo in any Hiera data file and no default supplied at /root/puppettests/hieratest.pp:1
Better than before :o)
so I do
mkdir /etc/puppetlabs/puppet/hieradata/
vi /etc/puppetlabs/puppet/hieradata/common.yaml
(remark: common is a member of the hierarchy in the hiera.yaml' and I enter
pippo : 'hello world!'

Again "puppet apply hieratest.pp":
notice: hello world!
Hurrah! My first hiera-based module!


No comments: