How to set up Hiera to you newly installed Puppetmaster

Hiera is a lightweight pluggable hierarchical database which can be useful, when you want to store your puppet-used data in a well organized structure.
Within this article I will show you how you can set it up for your puppetmaster (which was installed in my previous article).


I do not want to go into details, my purpose is only to show you how you can switch from “default” mode to a “hiera-based” one.
The hiera has been installed as dependency with the puppet-server package, no additional package installation is necessary.
By default the configuration file can be found under $confdir/hiera.yaml, which is in our case /etc/puppet/hiera.yaml (as we are using an open source version).
You have to create this file, because after the installation it will not be there. Here is a simple example how it should look like:

[root@PuppetMaster ~]# cat /etc/puppet/hiera.yaml

:backends:
– yaml
:yaml:
:datadir: /etc/puppet/hieradata/
:hierarchy:
– “%{clientcert}”
– “%{group}”
– “%{environment}”
– common
:logger: console

The format of the configuration file is YAML. I introduce the main settings with in a few sentences.
With “backend” you can define the backend in which format you will store your data. It can be yaml and json by default or you can also install other backends, like gpg.
If you define more backends, then Puppet will go in the defined sequence. The default value is yaml (as you see above). I will not change it now.
With the “hierarchy” we can define the way, where the puppet should look for parameters. The data sources in the hierarchy are checked in order, top to bottom.
It basically means that if a parameter is defined both in %{clientcert}.yaml file and in common.yaml then the value in %{clientcert}.yaml wins.
With datadir can we define where the yaml files can be found (If you leave it empty the default will be /var/lib/hiera).
With “logger” can be defined where the warnings and debug messages are routed. In our case it is set to console, which means that these will be sent to the STDERR.
If you want to use hiera, then it is recommended to define the used classes  within the yaml files and in /etc/puppet/manifests/site.pp.
To do that you have to add hiera_include(‘classes’) to /etc/puppet/manifests/site.pp, like in the following example:

[root@puppetmaster ~]# cat /etc/puppet/manifests/site.pp
hiera_include(‘classes’)

Here is an example how you can define the modules you want to include:
[root@PuppetMaster concar-plat-test]# cat common.yaml

classes:
– module_name_1
– module_name_2

It will do the same like you would set include module_name_1 and include module_name_2 into site.pp.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s