I think you're saying you want to process the fact data to produce an array of the IP addresses (except of the loopback interface) to assign as the value of the 'host_aliases' parameter of an 'sshkey' resource.
You can obtain an array of the interface name from the $interfaces fact like so:
$interface_names = split($::interfaces, ',')Given one interface name, you can interpolate the name into a string containing a template, then use the template to evaluate the desired Puppet variable, like so:
$interface_ipaddress = inline_template("<%= @ipaddress_${interface_name} %>")But the inline_template() can produce only a string, not an array, and by itself that does not address processing all the interfaces. I see three possible approaches:
- Write a custom function that computes the array of IP addresses for you
- Use "future" functions: especially reduce() and maybe reject(). This requires Puppet 3.2; see http://docs.puppetlabs.com/references/3.2.latest/function.html#reduce
- Use an inline template to produce a delimited string of the IP addresses, then split that to get the array you want.
I present a possible implementation of (3):
$interface_addresses = inline_template('<%=
@interface_names.reject{ |ifc| ifc == "lo" }.map{ |ifc| scope.lookupvar("ipaddress_#{ifc}") }.join(" ")
%>')
$interface_addr_array = split($interface_addresses, ' ')Note the use of
scope.lookupvar(), which is a different way to retrieve the value of a dynamically-chosen Puppet variable.
John