My /etc/puppetlabs/code
folder structure:
[vagrant@client code]$ pwd
/etc/puppetlabs/code
[vagrant@client code]$ tree
.
├── environments
│ ├── production
│ │ ├── environment.conf
│ │ ├── hieradata
│ │ ├── manifests
│ │ └── modules
│ └── test
│ ├── hieradata
│ ├── manifests
│ │ └── site.pp
│ └── modules
├── hieradata
│ ├── common.yaml
│ └── hostname
│ └── client.yaml
├── hiera.yaml
└── modules
Then, for my YAML files:
[vagrant@client code]$ cat hiera.yaml
---
:backends:
- yaml
:hierarchy:
- "hostname/%{facts.hostname}"
- "os/%{facts.osfamily}"
- common
:yaml:
:datadir: /etc/puppetlabs/code/hieradata
merge_behavior: deeper
[vagrant@client code]$ cat hieradata/common.yaml
---
users:
jill:
uid: 1000
home: '/home/jill'
jack:
uid: 1001
home: '/home/jack'
[vagrant@client code]$ cat hieradata/hostname/client.yaml
---
users:
jill:
home: '/homes/jill'
jack:
home: '/homes/jack'
jane:
uid : 999
home: '/homes/jane'
Yet, when I run hiera, I get the following:
[vagrant@client code]$ hiera --hash users
{"jill"=>{"uid"=>1000, "home"=>"/home/jill"},
"jack"=>{"uid"=>1001, "home"=>"/home/jack"}}
[vagrant@client code]$ hiera --hash users ::hostname=client
{"jill"=>{"uid"=>1000, "home"=>"/home/jill"},
"jack"=>{"uid"=>1001, "home"=>"/home/jack"}}
My hieradata/hostname/client.yaml
should be overriding the common.yaml
, causing the hiera
command to return something different when ::hostname=client
is handed in.
What am I doing wrong?
The $facts hash is set by the puppet agent / apply and I don't expect it to be available when you try validating your settings by hiera command line.
You can either use
- "hostname/%{::hostname}"
in your hierarchy to get the expected results from your hiera cmd or consider using the puppet command line to verify your settings instead.