I'm trying to merge hiera hashes using the lookup function as described here:
Here's my test:
Hiera config file:
==========================
---
version: 5
defaults:
datadir: hiera
data_hash: yaml_data
hierarchy:
- name: "Test 1"
path: "test1.yaml"
- name: "Test 2"
path: "test2.yaml"
==========================
File: "test1.yaml"
==========================
---
simple::package:
package1:
ensure: 'installed'
==========================
File: "test2.yaml"
==========================
---
simple::package:
package2:
ensure: 'installed'
==========================
Lookup works as expected - the first match is found.
puppet lookup --hiera_config ./hiera.yaml simple::package
==========================
---
package1:
ensure: installed
==========================
When merge strategy set to hash, the lookup returns results from both hiera files.
lookup --hiera_config ./hiera.yaml --merge hash simple::package
==========================
---
package2:
ensure: installed
package1:
ensure: installed
==========================
Everything makes sense to this point. Now to apply this in a manifest.
Here's my test class, specifying 'hash' merge strategy to lookup()
==========================
class simple (
Hash $package = lookup('simple::package', Hash, 'hash', {}),
) {
create_resources('Package',$package)
}
==========================
Apply (noop) the module, but only 'package1' gets defined as a package resource. Shouldn't the lookup
have merged the hashes? ('package2' is definately not already installed)
==========================
sudo puppet apply --modulepath=${modpath} --hiera_config=${hieraconf} --execute "include simple" --test --noop
Info: Loading facts
Info: Loading facts
Notice: Compiled catalog for mynode in environment production in 0.02 seconds
Info: Applying configuration version '1560036315'
Notice: /Stage[main]/Simple/Package[package1]/ensure: current_value 'purged', should be 'present' (noop)
Notice: Class[Simple]: Would have triggered 'refresh' from 1 event
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.22 seconds
==========================
I've tried setting the merge strategy in the class lookup function using string or hash syntax, with both
'hash' and 'deep' as the strategy, but can't get the class to merge the hashes. Am I missing something
with the lookup function?
$ puppet -V
5.5.14
# hiera -V
3.4.6