I'm using hiera with a YAML backend to manage my Puppet configuration and I'd like to append some values to an array.
I have a configuration file which looks a bit like this:
---
some_config:
- one
- two
- three
some_more_config:
- one
- two
- three
- four
Where some_more_config
is always a superset of some_config
.
I'd like to improve this file to remove the duplication but I haven't figured out whether it's possible or what the syntax would be:
---
some_config:
- one
- two
- three
some_more_config:
- "%{::some_config}"
- four
In words rather than code, some_more_config
is the entire contents of some_config
plus one additional value.
I don't think you can do that in Hiera because it can only interpolate string-based information (numbers are converted to strings) and not arrays or hashes.
From the Hiera 3: Interpolation Tokens, Variables, and Lookup Functions:
You can still do this via the Puppet DSL though. Here are a few options:
The Hiera 3: Lookup Types documentation covers this in detail, but if these were in multiple levels of the hierarchy you could merge them together using the
hiera_array()
method. Given how your hierarchy is set up, some hosts could get the smaller list, and some hosts could get the larger list.The puppetlabs-stdlib module can also help. It has concat and union methods for arrays.