I am running a masterless puppet setup that applies the puppet changes in the following manner.

puppet apply /tmp/puppet/manifests/site.pp --modulepath=/tmp/puppet/modules --hiera_config=/tmp/puppet/hiera.yaml

I have been trying to work in hiera to handle the different types of nodes we have and as a starting point have been trying to use a custom fact that is set on the nodes. This fact is nodetype and in this example is set to a value of diskless.

Facter on the node recognizes this fact.

# facter -y | grep nodetype
nodetype: diskless

And hiera.yaml contains the following

  - yaml
  :datadir: /tmp/puppet/data
  - node/%{::nodetype}

And at /tmp/puppet/data/node/diskless.yaml there is

cluster: blues

Though after doing so I try to double check that hiera is then setting variables as needed but it doesn't seem to work.

hiera -y diskless.yaml cluster

Is there a better way to debug the problem. I am sure it is something simple, though it would be disappointing if hiera doesn't (or can't) operate in this use case.


Edit 1:

Additional debugging

hiera cluster '::nodetype=diskless' -d
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Hiera YAML backend starting
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Looking up cluster in YAML backend
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Looking for data source defaults
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Cannot find datafile /var/lib/hiera/defaults.yaml, skipping
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Looking for data source global
DEBUG: Fri Oct 31 16:54:01 -0400 2014: Cannot find datafile /var/lib/hiera/global.yaml, skipping

Edit 2:

It appears setting the flag --hiera-config does nothing and one needs to symlink /etc/hiera.yaml to the hiera.yaml config you wish to use.

Edit 3: After symlinking /etc/hiera.yaml to /tmp/puppet/hiera.yaml I was able to lookup hiera variables but was not able to use them in puppet manifests in the expected way. Instead I had to call hiera like so directly

$networking_config    = hiera('networking::network::networking_config','no')

Terribly confusing


Try this:

hiera cluster '::nodetype=diskless'

See: https://docs.puppetlabs.com/hiera/1/command_line.html#fact-sources

  • Unfortunately that also returns nil just as 'hiera -y diskless.yaml cluster' returned nil. – Wilshire Oct 30 '14 at 1:42
  • 1
    @Wilshire What's the output if you add -d to that command? – Shane Madden Oct 31 '14 at 20:40
  • Adding the information to the question – Wilshire Oct 31 '14 at 20:54
  • 1
    Debug shows hiera searching /var/lib/hiera but the hiera.yaml in your original question has ':datadir: /tmp/puppet/data'. Command line hiera uses /etc/hiera.yaml but puppet by default uses /etc/puppet/hiera.yaml. Normally those are symlinked but if not that might explain what you're seeing. – Ian Nov 2 '14 at 22:35
  • 1
    I don't know which hiera.yaml puppet was using but your tests with hiera from the command line were using /etc/hiera.yaml (as shown by the debug output). – Ian Nov 4 '14 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.