I recently got stumped doing a training course trying to demonstrate moving global data to the environment layer and came across this behaviour - If this is intended behaviour then it really needs to be documented well because (for me) this was seems really confusing.
Summary
Lookups will always prioritise data found in /etc/puppetlabs/puppet/data/ even if no global level lookup has been configured.
Set up
Version 4.10.1
[root@devagent puppetlabs]# puppet -V
|
4.10.1
|
One hiera.yaml file at the environment level - no global configuration file.
[root@devagent puppetlabs]# find /etc/puppetlabs -name hiera.yaml
|
/etc/puppetlabs/code/environments/production/hiera.yaml
|
|
[root@devagent puppetlabs]# cat /etc/puppetlabs/code/environments/production/hiera.yaml
|
version: 5
|
hierarchy:
|
- name: "test"
|
path: "common.yaml"
|
data_hash: yaml_data
|
datadir: hieradata
|
Steps
1) Populate the environment data
[root@devagent puppetlabs]# echo -n "foo::bar: from the environment" > /etc/puppetlabs/code/environments/production/hieradata/common.yaml
|
[root@devagent puppetlabs]# puppet lookup foo::bar
|
--- from the environment
|
...
|
2) ... so far so good ... now if we leave some data in the global layer, which we've not configured anywhere, it's used by default....
[root@devagent puppetlabs]# echo -n "foo::bar: WTF?" > /etc/puppetlabs/puppet/data/common.yaml
|
[root@devagent puppetlabs]# puppet lookup foo::bar
|
--- WTF?
|
...
|
With explain turned on....
[root@devagent puppetlabs]# puppet lookup foo::bar --explain
|
Searching for "lookup_options"
|
Global Data Provider (hiera configuration version 5)
|
Hierarchy entry "Common"
|
Path "/etc/puppetlabs/puppet/data/common.yaml"
|
Original path: "common.yaml"
|
No such key: "lookup_options"
|
Environment Data Provider (hiera configuration version 5)
|
Using configuration "/etc/puppetlabs/code/environments/production/hiera.yaml"
|
Hierarchy entry "test"
|
Path "/etc/puppetlabs/code/environments/production/hieradata/common.yaml"
|
Original path: "common.yaml"
|
No such key: "lookup_options"
|
Module data provider for module "foo" not found
|
Searching for "foo::bar"
|
Global Data Provider (hiera configuration version 5)
|
Hierarchy entry "Common"
|
Path "/etc/puppetlabs/puppet/data/common.yaml"
|
Original path: "common.yaml"
|
Found key: "foo::bar" value: "WTF?"
|
So it seems the global level will always get looked up even when the user hasn't configured it and will use defaults - so if old / obsolete data is found in the global default datadir then it gets prioritised over whats configured and this, to me, is confusing behaviour.
|