4

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

Wilshire
  • 538
  • 6
  • 19

1 Answers1

5

Try this:

hiera cluster '::nodetype=diskless'

See fact-sources documentation

рüффп
  • 620
  • 1
  • 11
  • 24
Ian
  • 366
  • 1
  • 6
  • Unfortunately that also returns nil just as 'hiera -y diskless.yaml cluster' returned nil. – Wilshire Oct 30 '14 at 01: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 02 '14 at 22:35
  • @Ian You mention /etc/hiera.yaml and it does exist but why would puppet be even looking at it when I specify where the hiera.yaml file is with the --hiera-config flag? I do see that there is a template /etc/hiera.yaml file so I went ahead and symlinked that to the copy of hiera.yaml it should be using (/tmp/puppet/hiera.yaml) and it seems to work now. I guess --hiera-config just gets ignored. – Wilshire Nov 03 '14 at 17:05
  • 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 04 '14 at 03:40
  • @Wilshire Where'd you find that option, `puppet.conf`?? According to the [docs](https://docs.puppetlabs.com/hiera/1/command_line.html#options), for the `hiera` command, it's `-c` or `--config`, not `--hiera_config`. – Shane Madden Nov 04 '14 at 17:40
  • Fairly certain is was from a puppet book that I got a while back, before hiera was baked in with Puppet and was still something you had to grab from a third party source. Unfortunately the -c and --config doesn't help. – Wilshire Nov 04 '14 at 19:45