Codebase list facter / 6b1cd16
(#6614) Update ipaddress6 fact to work with Ruby 1.9 Calling #to_s on an Array such as ["foo"] in Ruby 1.9 will result in the string '["foo"]', instead of stringifying the element in the array which would have given the expected result of "foo". Since the element of the array we're dealing with is already a string, we can just grab it out of the array by using #first. Paired-with: Josh Cooper <josh@puppetlabs.com> Jacob Helwig 13 years ago
1 changed file(s) with 17 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
2020 # Used the ipaddress fact that is already part of
2121 # Facter as a template.
2222
23 def get_address_after_token(output, token, return_first=false)
24 ip = nil
25
26 output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match|
27 match = match.first
28 unless match =~ /fe80.*/ or match == "::1"
29 ip = match
30 break if return_first
31 end
32 end
33
34 ip
35 end
36
2337 Facter.add(:ipaddress6) do
2438 confine :kernel => :linux
2539 setcode do
26 ip = nil
2740 output = Facter::Util::Resolution.exec('/sbin/ifconfig')
2841
29 output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
30 str = str.to_s
31 unless str =~ /fe80.*/ or str == "::1"
32 ip = str
33 end
34 }
35
36 ip
37
42 get_address_after_token(output, 'inet6 addr:')
3843 end
3944 end
4045
4247 confine :kernel => %w{SunOS}
4348 setcode do
4449 output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a')
45 ip = nil
4650
47 output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
48 str = str.to_s
49 unless str =~ /fe80.*/ or str == "::1"
50 ip = str
51 end
52 }
53
54 ip
55
51 get_address_after_token(output, 'inet6')
5652 end
5753 end
5854
6056 confine :kernel => %w{Darwin FreeBSD OpenBSD}
6157 setcode do
6258 output = Facter::Util::Resolution.exec('/sbin/ifconfig -a')
63 ip = nil
6459
65 output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str|
66 str = str.to_s
67 unless str =~ /fe80.*/ or str == "::1"
68 ip = str
69 break
70 end
71 end
72
73 ip
60 get_address_after_token(output, 'inet6', true)
7461 end
7562 end
76