On Wednesday, August 14, 2013 5:20:41 AM UTC-5, Christian Reiß wrote:
>
> Hello all,
>
> I am trying to set up ssh keys (sshkeys) for populate
> /etc/ssh/ssh_known_hosts. So far it works great, but I want to have aliases
> for all ips online on that host.
>
> Two problems:
>
> - The assumption is that the interface count and names are unknown. There
> can be one eth or many, none but a xapi device etc. There is, however,
> interfaces variable from facter, which holds all the interfaces.
>
> - I need to loop through the array and use the contents of that variable,
> ie:
>
> interfaces => eth0,eth1,lo,tun0
> ipaddress => 46.229.47.132
> ipaddress_eth0 => 46.229.47.132
> ipaddress_eth1 => 10.1.0.2
> ipaddress_lo => 127.0.0.1
> ipaddress_tun0 => 10.10.0.1
>
> So I would need to loop through interfaces, query the variable with the
> same name to get the ip address. All this by acoiding loopback.
>
> - I dont know a good way to then add all compiled aliases into sshkeys.
>
> Does anyone have a pointer / solution?
>
>
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:
1. Write a custom function that computes the array of IP addresses for
you
2. 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
3. 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
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.