Aim
The aim is to reuse hiera arrays to avoid code duplication.
Attempts
The following array has been defined in a hiera.yaml file:
hiera_array:
- host1
- host2
- host3
In an attempt to reuse it, the hiera_array is set to be used by another hiera array:
reuse::hiera_array:
- "%{hiera('hiera_array')}"
Expected outcome
There should be no discrepancy between the files if hiera_array
or reuse::hiera_array
is called:
filename.erb
<%= scope.function_hiera(['reuse::hiera_array']).join("\n") %>
/path/to/filename
host1
host2
host3
Current outcome
However the filename.erb template that calls the array returns:
/path/to/filename
-host1
-host2
-host3
+["host1, host2, host3"]
Removing the join
from the templates indicates that the looked up hiera array looks different:
["[\"host1\", \"host2\", \"host3\"]"]
vs. ["host1", "host2", "host3"]
Discussion
It looks like that the hiera_array can be reused as ["host1, host2, host3"]
is returned and looks like an array. However the hiera or the erb function <%= scope.function_hiera(['reuse::hiera_array']).join("\n") %>
interprets it as a string.
Question
How to reuse Hiera arrays in Puppet?