January 14, 2015

Puppet – Hiera troubleshooting

There will be times when Hiera just isn’t returning the information that you are expecting from it. In these situations you need to do a bit of digging. The first place to start is looking at hiera’s help info:


You can find all my latest posts on medium.

[root@puppetmaster yaml]# hiera --help
Usage: hiera [options] key [default value] [variable='text'...]

The default value will be used if no value is found for the key. Scope variables
will be interpolated into %{variable} placeholders in the hierarchy and in
returned values.

    -V, --version                    Version information
    -d, --debug                      Show debugging information
    -a, --array                      Return all values as an array
    -h, --hash                       Return all values as a hash
    -c, --config CONFIG              Configuration file
    -j, --json SCOPE                 JSON format file to load scope from
    -y, --yaml SCOPE                 YAML format file to load scope from
    -m, --mcollective IDENTITY       Use facts from a node (via mcollective) as scope
    -i, --inventory_service IDENTITY Use facts from a node (via Puppet's inventory service) as scope
[root@puppetmaster yaml]#

Note: using the “debug” is really helpful.

Also check out the hiera_explain gem:

Also here’s a way to do hiera lookup straight from the command line:

PUPPET_GEM_VERSION=3.7.5 bundle exec puppet apply --parser=future -e "notice(hiera('foo', undef))"

However this doesn’t output the value of anything. but it confirms that it found something

See also: (which shows how to force puppet to only use hiera data)