3

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.

womble
  • 95,029
  • 29
  • 173
  • 228
Arijit Ghosh
  • 31
  • 1
  • 3

1 Answers1

2

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:

If any of the matched values are arrays, they’re flattened and included in the results.

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.

womble
  • 95,029
  • 29
  • 173
  • 228