Skip to content

Commit

Permalink
add custom function which returns all ipaddresses as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Nov 23, 2012
1 parent c6fe1c3 commit b0a64a6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/puppet/parser/functions/ipaddresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Puppet::Parser::Functions
newfunction(:ipaddresses, :type => :rvalue, :doc => <<-EOS
Returns all ip addresses of network interfaces (except lo) found by facter.
EOS
) do |args|
interfaces = lookupvar('interfaces')

return false if (interfaces == :undefined)

result = []
if interfaces.count(',') > 0
interfaces = interfaces.split(',')
interfaces.each do |iface|
if ! iface.include?('lo')
ipaddr = lookupvar("ipaddress_#{iface}")
ipaddr6 = lookupvar("ipaddress6_#{iface}")
if ipaddr
result << ipaddr
end
if ipaddr6
result << ipaddr6
end
end
end
else
if ! interfaces.include?('lo')
ipaddr = lookupvar("ipaddress_#{interfaces}")
ipaddr6 = lookupvar("ipaddress6_#{interfaces}")
if ipaddr
result << ipaddr
end
if ipaddr6
result << ipaddr6
end
end
end

return result
end
end

0 comments on commit b0a64a6

Please sign in to comment.