The goal
Be able to assign modules to nodes in Puppet with an external source of information.
This will allow to programmatically assign puppet modules to nodes and parameters to puppet modules.
And ease the development of frontends like a web interface for this task.
There are several approaches for this like External node classifiers and Hiera.
I chose Hiera, which is a datastore, with a redis database backend which is easy to query and update.
References
This is a digest and how-to of these highly recommended readings :
The problem with separating data from puppet code
First look installing and using Hiera - Puppetlabs
Hiera-redis - Reliantsecurity - Github
Install Hiera
On the puppet master.
Debian-like systems :
1 2 3 4 5 6 7 8 9 | |
Red Hat EL 6 :
1 2 3 4 | |
Then :
1 2 3 4 5 6 | |
ATOW, the master branch was broken for my Puppet (2.7.11). I had to use a fix :
1 2 3 4 5 6 7 | |
Many thanks to Volcane (R.I. pienaar) and Kelsey Hightower for the debugging.
It should be fine with the master branch in the version 1.0+
Now you need to synchronize the custom Hiera functions into the master.
Just restart the puppetmaster.
If needed, in addition, force the synchronisation with the following procedure.
On the master, with pluginsync=true in the [main] section of the puppet.conf :
1 2 | |
Configure hiera
Puppet expects a configuration file /etc/puppet/hiera.yaml
Here is a basic one :
1 2 3 4 5 6 7 8 9 10 | |
I set the hiera datadir in a subfolder of /etc/puppet to ease the backup of my puppet data (/etc/puppet/{manifests,modules,hieradata}).
Create the “datastore” :
1
| |
Create a basic database /etc/puppet/hieradata/common.yaml :
1 2 | |
Test with :
1
| |
Test with a basic manifest
For example :
1 2 3 4 5 6 | |
Use some parameters set in hiera
As an example let’s use some parameters for a module dealing with jboss.
In /etc/puppet/hieradata/common.yaml
1 2 | |
You can use this in a manifest with :
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
hiera('jboss::up', true) means that puppet should failback to true if the key is not found in hiera.
Assign modules to nodes
We can assign classes to a single node, to a subset of nodes or to all nodes as default classes.
For example, in hiera.yaml, you can set a hierarchy :
1 2 3 4 | |
You can use any standard or custom facter fact in your hierarchy.
With the hierarchy above, and a Red Hat puppet client named infrmon01, we could have three yaml files in the folder hieradata :
common.yamlRedHat.yamlinfrmon01.yaml
In common.yaml we set the classes applied to all nodes :
1 2 | |
In RedHat.yaml, we set the classes applied to all Red Hat systems :
1 2 | |
In infrmon01.yaml, we set the classes applied to this specific host :
1 2 | |
Note : you need to respect a whitespace after the comma.
And in your site manifest :
1 2 3 | |
Again, '' is the failback.
hiera_include will merge all the arrays down the hierarchy giving you the combined classes list for each node.
Switch the backend to redis
1 2 | |
In /etc/puppet/hiera.yaml, add or switch to the new backend :
1 2 3 4 5 | |
Note : in the version of hiera-redis that I use, I need at least a parameter in :redis to avoid a bug undefined method 'has_key?'
Insert your data into redis.
For example, to set :
1 2 3 | |
you can use the redis CLI :
1 2 3 4 5 6 | |
Note : true in the yaml file was used as a boolean in puppet, but it is a string with redis. This is the reason of :
1
| |
in the manifest above.
The mapping between puppet classes and nodes is done like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
WebUI
This is what it looks like in the Kermit Web UI (development version, so far) :