Can any Puppet and Hiera experts out there help me out with this annoying situation I'm seeing?
Hiera works fine for anything in common.yaml
:
cat common.yaml
---
resolv_conf::nameserver:
- x.x.x.x
- x.x.x.x
profile::ntp::servers:
- x.x.x.x
- x.x.x.x
Then tested with the following works:
hiera resolv_conf::nameservers environment=production
["x.x.x.x", "x.x.x.x"]
So, the above works as expected. However, if I use a nodes
directory inside hieradata
and add test data in:
cat nodes/fqdn.yaml
---
profile::ntp::servers:
-1.1.1.1
-2.2.2.2
Then I adjust my hiera.yaml
file accordingly:
cat hiera.yaml
---
:backends: yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
:hierarchy:
-"nodes/%{::fqdn}"
- "common"
:logger: console
:merge_behavior: native
:deep_merge_options: {}
And also add the correct line into the global hiera.yaml
(both files now look the same for testing).
When testing I get the following error:
hiera profile::ntp::servers environment=production -d
DEBUG: xxxxxxxxx: Hiera YAML backend starting
DEBUG: xxxxxxxxx: Looking up profile::ntp::servers in YAML backend
DEBUG: xxxxxxxxx: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: xxxxxxxxx: Looking for data source common
DEBUG: xxxxxxxxx: Found profile::ntp::servers in common
["x.x.x.x", "x.x.x.x"]
So it finds the values in common
but doesn't like the nodes
directory.
I have tried loads of different variations of the hierarchy
line in hiera.yaml
, and many different options everywhere else I can imagine!
There may be typos in the above, as I had to type it all out manually as I have no copy and paste, but I have checked the live files again and again for typos and syntax errors.
Any ideas?
Some updates now I'm home and can copy/paste:
This is on a fresh install of puppet enterprise, using code manager and gitlab.
[root@client-01 nodes]# pwd
/root/control-repo/hieradata/nodes
[root@client-01 nodes]# ll
total 8
-rw-r--r--. 1 root root 34 Jul 13 19:04 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 18:58 test.yaml
[root@client-01 nodes]# cat puppet.example.com.yaml
---
message:
- "This is in nodes"
This is on a dev machine, the repo was then pushed which initiated the hook for code deploy, I've checked that the same data is available in /etc/puppetlabs/code/environments/production etc on the puppet master. So Code Manager is working.
The following tests on the puppet server:
[root@puppet ~]# hostname -f
puppet.example.com
[root@puppet ~]# hiera message environment=production
nil
[root@puppet ~]# hiera message environment=production
fqdn=puppet.example.com
nil
[root@puppet ~]# hiera message environment=production fqdn=puppet.example.com -d
DEBUG: 2017-07-13 19:28:15 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 19:28:15 +0100: Looking up message in YAML backend
DEBUG: 2017-07-13 19:28:15 +0100: Ignoring bad definition in :hierarchy: 'nodes/'
DEBUG: 2017-07-13 19:28:15 +0100: Looking for data source common
nil
[root@puppet ~]#
And so it looks like exactly the same problem:
My hiera.yaml
:
[root@puppet ~]# cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
- yaml
:hierarchy:
- "nodes/%{::fqdn}"
- common
:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
This is somewhat reassuring as it means maybe there isn't something majorly wrong with the other puppet server and more than likely something I'm doing wrong?
FURTHER EDIT:
So I didn't have too much time last night to test things but I did find this:
It looks like the problem is with the facter variables i.e. `"%{::fqdn}"
If I do the following in the root of hieradata:
[root@client-01 hieradata]# pwd ; ll ; cat test.yaml
/root/control-repo/hieradata
total 12
-rw-r--r--. 1 root root 4 Jul 13 19:25 common.yaml
drwxr-xr-x. 2 root root 52 Jul 13 19:04 nodes
-rw-r--r--. 1 root root 19 Jul 13 21:47 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 21:43 test.yaml
---
name:
- "jon"
Then test with hiera name environment=production
it works fine.
If I do the following in the root of hieradata:
[root@client-01 hieradata]# pwd ; ll ; cat puppet.example.com.yaml
/root/control-repo/hieradata
total 12
-rw-r--r--. 1 root root 4 Jul 13 19:25 common.yaml
drwxr-xr-x. 2 root root 52 Jul 13 19:04 nodes
-rw-r--r--. 1 root root 19 Jul 13 21:47 puppet.example.com.yaml
-rw-r--r--. 1 root root 18 Jul 13 21:43 test.yaml
---
test:
- "pass"
Then I test in the following ways:
[root@puppet ~]# hostname -f ; hiera test environment=production -d
puppet.example.com
DEBUG: 2017-07-13 21:53:44 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 21:53:44 +0100: Looking up test in YAML backend
DEBUG: 2017-07-13 21:53:44 +0100: Ignoring bad definition in :hierarchy:
'nodes/'
DEBUG: 2017-07-13 21:53:44 +0100: Ignoring bad definition in :hierarchy: ''
DEBUG: 2017-07-13 21:53:44 +0100: Looking for data source test
DEBUG: 2017-07-13 21:53:44 +0100: Looking for data source common
nil
[root@puppet ~]# hostname -f ; hiera test environment=production
fqdn=puppet.example.com -d
puppet.example.com
DEBUG: 2017-07-13 21:53:57 +0100: Hiera YAML backend starting
DEBUG: 2017-07-13 21:53:57 +0100: Looking up test in YAML backend
DEBUG: 2017-07-13 21:53:57 +0100: Ignoring bad definition in :hierarchy:
'nodes/'
DEBUG: 2017-07-13 21:53:57 +0100: Ignoring bad definition in :hierarchy: ''
DEBUG: 2017-07-13 21:53:57 +0100: Looking for data source test
DEBUG: 2017-07-13 21:53:57 +0100: Looking for data source common
nil
So disregarding the subfolder of nodes entirely and testing in the root of hieradata shows that yaml files with a fixed name work, but when using facter for a per node lookup... this is where the failure is.
[root@puppet ~]# facter fqdn
puppet.example.com
[root@puppet ~]# hostname -f
puppet.example.com
However, facter seems to be working just fine.
Any help would be greatly appreciated, thanks. Jon