Ask Your Question
0

Hiera Lookup Options

asked 2017-01-24 08:06:34 -0500

puser gravatar image

My Hiera Data is as follows:

 ---
lookup_options:
  site::purge::rules:
    merge:
    strategy: hash
    merge_hash_arrays: true

I want to be able to merge any arrays for the given hiera value site::purge::rules but if there is a conflict I want the higher tier to take priority.

For example:

If my Hiera router looks like this:

---
:backends:
  - yaml
:hierarchy:
 - "clientcert/%{::clientcert}"
- "global"
:yaml:
  :datadir: "/home/user/puppet/hieradata"

Then the "Global" values should take priority over clientcert data if they conflict.

if I have data like in GLOBAL.yaml

---
site::purge::rules:
- 'tmp.conf':
  directory: '/tmp'
  daystokeep: '365'
  wildcardExp: '{*,.*}'
  options: 'R'

Then in a CLIENTCERT.yaml I have:

anfsite::purge::rules:
 - 'tmp.conf':
  directory: '/tmp'
  daystokeep: '150'
  wildcardExp: '{*,.*}'
  options: 'R'
 - 'var-log.conf':
  directory: '/var/log'
  daystokeep: '365'
  wildcardExp: '*.log'
  options: ''

the resulted array should be:

---
site::purge::rules:
- 'tmp.conf':
  directory: '/tmp'
  daystokeep: '365'
  wildcardExp: '{*,.*}'
  options: 'R'
- 'var-log.conf':
  directory: '/var/log'
  daystokeep: '365'
  wildcardExp: '*.log'
  options: ''

Note the daystokeep is 365 from the higher priority global.yaml yet the var-log was still included.

What lookup options do I need to make this work?

thanks,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-01-24 14:55:45 -0500

puser gravatar image

I am going to answer my own question:

In order for this to work I had to drop the hiera data from an array to a hash. So instead of an array of hashes it was a hash of hashes like:

anfsite::purge::rules:
 'tmp.conf':
  directory: '/tmp'
  daystokeep: '150'
  wildcardExp: '{*,.*}'
  options: 'R'
'var-log.conf':
  directory: '/var/log'
  daystokeep: '365'
  wildcardExp: '*.log'
  options: ''

This allowed the usage of

---
lookup_options:
  site::purge::rules:
  merge:
  strategy: deep
  merge_hash_arrays: true

The above lookup_options were not allowed because it only works on hashes and I was trying to use an array of hashes. I think it is probably best to stick to either all hashes or all arrays if you are doing nesting.

edit flag offensive delete link more

Comments

I was thinking something similar to that, arrays are 'tricky' to merge, so I believe it treats an array as a single leaf object, and pulls in the 'highest' value

DarylW gravatar imageDarylW ( 2017-01-24 18:54:06 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-01-24 08:06:34 -0500

Seen: 187 times

Last updated: Jan 24