Getting Hiera Working24 July 2012 · Filed in Explanation
As I mentioned in a previous post, the next iteration of my Puppet explorations involves the use of Hiera. Hiera, a project also managed by Puppet Labs, is described as “a simple pluggable hierarchical database.” In the Puppet world, what that means is we can use Hiera to store data values outside of the manifests, then look them up dynamically as the configurations are being compiled and applied to the nodes. In a future post, I’ll provide an example of how you could use Hiera in a multi-OS Puppet environment.
For now, though, I just want to talk about how to get Hiera up and running and working in a Puppet environment, as it wasn’t as straightforward as I expected it to be.
I’m using the same virtual environment for this post as I’ve used in previous posts. I have a Puppet master server running on an Ubuntu 12.04 LTS VM; this master server services client VMs running Ubuntu 12.04 LTS, CentOS 5.8, and OpenBSD 5.1. Keep in mind that if you are using a different distribution of Linux than what I’m using here, your specific directories and paths might be slightly different.
Here are the steps that I took to get Hiera up and running on the Puppet master server:
First, I used
gem install hiera hiera-puppetto install Hiera and Hiera-Puppet (the connecting code between Hiera and Puppet).
Optionally, you can next run
gem listto verify that Hiera and Hiera-Puppet are included in the list of installed Ruby gems.
You’ll need to know exactly where the Hiera-Puppet files are found on your system, so run
gem list -dto show the details of the installed gems. This will include the path where the files are found. On my Ubuntu 12.04 LTS Puppet master server, Hiera and Hiera-Puppet were installed to
/var/lib/gems/1.8/gems(in their own directories, respectively).
Next, you’ll need to know where Puppet stores its modules. Run
puppet master --configprint modulepathto get the list of directories where Puppet modules are stored. On my Ubuntu 12.04 LTS Puppet master server, that included
Copy the Hiera-Puppet directory (found in step 3) to one of the Puppet module directories (found in step 4). This ensures that Puppet can actually leverage Hiera. Note that this Puppet Labs post provides a different process for accomplishing this; I found that their process didn’t work in my environment.
Hiera will need a directory to store its configuration files; I used
/etc/puppet/hieradata. I don’t think it matters where the directory is; just make a note of where.
You’ll need to create a Hiera configuration file located in the main Puppet directory (on my Ubuntu 12.04 LTS Puppet master server, this was
/etc/puppet). This file is called
hiera.yamland will probably need to look something like this (you’d specify the directory created in step 6 on the last line here):
At this point, you should now have a working Hiera installation. In a future post, I’ll show you how I used Hiera with Puppet to create OS-based customized configuration files.
In the directory you created for Hiera and specified in
hiera.yaml, you’ll need to create the YAML files for your hierarchy. Since I’m using a hierarchy based on operating system, I created YAML files for OpenBSD, CentOS, Ubuntu, etc. One note: the file names must match the operating system name returned by Facter exactly, including case (i.e.,
OpenBSD.yaml instead of
In working to get Hiera up and running, I found the following websites and pages to be helpful:
Corrections, suggestions for improvement, or questions are always welcome! Speak up in the comments below.Tags: Automation · BSD · Interoperability · Linux · OSS · UNIX Previous Post: Seeking Feedback on Infrastructure Coders Denver Next Post: Advanced Spotlight Queries in the Mac GUI