Trouble using hiera in masterless setup and getting values set for classes

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

---
:backends:
  - yaml
:yaml:
  :datadir: /tmp/puppet/data
:hierarchy:
  - 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
nil

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.

Cheers

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
nil

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


Solution 1:

Try this:

hiera cluster '::nodetype=diskless'

See fact-sources documentation