|
1 | 1 | module Puppet::Parser::Functions |
2 | | - newfunction(:ipaddresses, :type => :rvalue, :doc => <<-EOS |
| 2 | + newfunction(:ipaddresses, type: :rvalue, doc: <<-EOS |
3 | 3 | Returns all ip addresses of network interfaces (except lo) found by facter. |
4 | 4 | EOS |
5 | | - ) do |args| |
6 | | - interfaces = lookupvar('interfaces') |
| 5 | + ) do |_args| |
| 6 | + interfaces = lookupvar('interfaces') |
7 | 7 |
|
8 | | - # In Puppet v2.7, lookupvar returns :undefined if the variable does |
9 | | - # not exist. In Puppet 3.x, it returns nil. |
10 | | - # See http://docs.puppetlabs.com/guides/custom_functions.html |
11 | | - return false if (interfaces.nil? || interfaces == :undefined) |
| 8 | + # In Puppet v2.7, lookupvar returns :undefined if the variable does |
| 9 | + # not exist. In Puppet 3.x, it returns nil. |
| 10 | + # See http://docs.puppetlabs.com/guides/custom_functions.html |
| 11 | + return false if interfaces.nil? || interfaces == :undefined |
12 | 12 |
|
13 | | - result = [] |
14 | | - if interfaces.count(',') > 0 |
15 | | - interfaces = interfaces.split(',') |
16 | | - interfaces.each do |iface| |
17 | | - if ! iface.include?('lo') |
18 | | - ipaddr = lookupvar("ipaddress_#{iface}") |
19 | | - ipaddr6 = lookupvar("ipaddress6_#{iface}") |
20 | | - if ipaddr and (ipaddr!= :undefined) |
21 | | - result << ipaddr |
22 | | - end |
23 | | - if ipaddr6 and (ipaddr6!= :undefined) |
24 | | - result << ipaddr6 |
25 | | - end |
26 | | - end |
27 | | - end |
28 | | - else |
29 | | - if ! interfaces.include?('lo') |
30 | | - ipaddr = lookupvar("ipaddress_#{interfaces}") |
31 | | - ipaddr6 = lookupvar("ipaddress6_#{interfaces}") |
32 | | - if ipaddr and (ipaddr!= :undefined) |
33 | | - result << ipaddr |
34 | | - end |
35 | | - if ipaddr6 and (ipaddr6!= :undefined) |
36 | | - result << ipaddr6 |
37 | | - end |
38 | | - end |
39 | | - end |
40 | | - |
41 | | - return result |
| 13 | + result = [] |
| 14 | + if interfaces.count(',') > 0 |
| 15 | + interfaces = interfaces.split(',') |
| 16 | + interfaces.each do |iface| |
| 17 | + next if iface.include?('lo') |
| 18 | + ipaddr = lookupvar("ipaddress_#{iface}") |
| 19 | + ipaddr6 = lookupvar("ipaddress6_#{iface}") |
| 20 | + result << ipaddr if ipaddr && (ipaddr != :undefined) |
| 21 | + result << ipaddr6 if ipaddr6 && (ipaddr6 != :undefined) |
| 22 | + end |
| 23 | + else |
| 24 | + unless interfaces.include?('lo') |
| 25 | + ipaddr = lookupvar("ipaddress_#{interfaces}") |
| 26 | + ipaddr6 = lookupvar("ipaddress6_#{interfaces}") |
| 27 | + result << ipaddr if ipaddr && (ipaddr != :undefined) |
| 28 | + result << ipaddr6 if ipaddr6 && (ipaddr6 != :undefined) |
| 29 | + end |
42 | 30 | end |
| 31 | + |
| 32 | + return result |
| 33 | + end |
43 | 34 | end |
0 commit comments