merging hashes with puppet lookup function

15 views
Skip to first unread message

Chris Southall

unread,
Jun 9, 2019, 11:16:42 AM6/9/19
to Puppet Users
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


Henrik Lindberg

unread,
Jun 10, 2019, 5:38:38 AM6/10/19
to puppet...@googlegroups.com
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/

Reply all
Reply to author
Forward
0 new messages