1
votes

I am trying to read a key present in multiple hiera files and merge the values. My hiera file contains:

hierarchy:
  - name: "Per-env secrets"
    paths:
      - "puppet/hiera/dict-1.yaml"
      - "puppet/hiera/dict-2.yaml"

and My puppet script contains:

lookup(dictionaries,Hash).each |String $keyDico, Hash $valueDico| {
  notify{"The value of dictionary is: ${keyDico}": }

The key 'dictionaries' is present in both dict-1.yaml and dict-2.yaml. However, It always reads and prints the Key from the first matched hiera file.
I tried changing 'Hash' in lookup function's argument to 'Unique' or 'Deep'. But it didn't work.

Getting error: Error: Evaluation Error: Resource type not found: Deep and Error: Evaluation Error: Resource type not found: Unique
Is there any way to achieve this?

Thanks in advance.

1

1 Answers

3
votes

If you look at the docs for specifying merge behaviours (ref), you can see that you need to specify the optional third argument to lookup, and you are getting that error because "unique" is being interpreted as the data type.

Try either:

lookup(dictionaries, Hash, 'unique')

or

lookup(dictionaries, Hash, {'strategy' => 'unique'})

according to whichever you find more readable.