I have a situation where I have to generate array of arrays which are declared in hiera in puppet at different hierarchies.
Lets say at environment level I have a declaration
test:
- [a,b,c,d]
- [e,f,g,h]
and at common.yaml I have a declaration
test:
- [i,j,k,l]
- [m,n,o,p]
Now, when I pass the hiera_array
value I want the output as
[[i,j,k,l],[m,n,o,p],[a,b,c,d],[e,f,g,h]]
currently the output is [i,j,k,l......e,f,g,h]
basically in one merged array value.
I want it in array of array format so that I can pas that to a template and apply it to required logic. Please tell me if there is any way to achieve this.
Best Answer
You are, I believe, doomed (in general). The
hiera_array
documentation specifically mentions that the values returned are a "flattened array". It further clarifies the situation:Now, if your example is accurate as to structure, and each of your arrays is guaranteed to have four scalar elements, you can do some hacks to take the array four elements at a time, and "reconstruct" the original structure. I don't know of a built-in function to do this, but a custom parser function to group the elements into groups of four wouldn't be hard to write.