Facter displaying multiple IP addresses?

418 views
Skip to first unread message

Will S. G.

unread,
Feb 12, 2012, 10:01:01 PM2/12/12
to Puppet Users
Hi,

I have a motd module (not mine) that rewrites /etc/motd with some
useful host details. One particular piece of information is the IP
address in motd.erb:

FQDN: <%= fqdn %>
IP: <%= ipaddress %>

I have several hosts that have multiple IP addresses, and I need to
display them as well. When I run facter | grep ipaddress, I get an
array:

ipaddress => 172.26.20.16
ipaddress_eth0 => 172.26.20.16
ipaddress_eth1 => 10.20.30.5
ipaddress_eth2 => 10.20.40.5
ipaddress_eth3 => 10.20.50.5
ipaddress_eth4 => 10.20.60.5
ipaddress_eth5 => 10.20.70.5

Is there a way to display eth{0-5} as well?


Gonzalo Servat

unread,
Feb 12, 2012, 11:38:09 PM2/12/12
to puppet...@googlegroups.com
On Mon, Feb 13, 2012 at 2:01 PM, Will S. G. <wi...@arw.in> wrote:

Is there a way to display eth{0-5} as well?

You could do a for loop from 0 to N (5?) and check if the variable exists (if has_variable?("ipaddress_eth" + index)) then print it. I'm sure there's probably a nicer way of doing this in Ruby :)

- Gonzalo

Torbjörn Norinder

unread,
Feb 13, 2012, 5:32:52 AM2/13/12
to puppet...@googlegroups.com
You could do

IP: <%= scope.to_hash.inject([]) { |acc, (k,v)| acc << v if k =~ /^ipaddress_/; acc }.join(', ') %>

Regards,

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>

--
Torbj�rn Norinder

Campanja AB
Kammakargatan 9A
11140 Stockholm
Map: http://ow.ly/NUlS
www.campanja.com

Reply all
Reply to author
Forward
0 new messages