On 2019-06-09 02:34, Chris Southall wrote:
I'm trying to merge hiera hashes using the lookup function as described
here:
https://puppet.com/docs/puppet/5.5/hiera_automatic.html#puppet-lookup
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
By default automatic loopkup uses priority. To change that you should
use "lookup_option" that is set in your data. This is documented here:
https://puppet.com/docs/puppet/6.4/hiera_merging.html#concept-2997
Hope that helps.
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/qdl8eg%246h5g%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.