Bug #10278
some facts do not work with locales set
| Status: | Needs More Information | Start date: | 10/25/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | interface | |||
| Target version: | 1.6.x | |||
| Keywords: | locale | Affected Facter version: | 1.6.2 | |
| Branch: | ||||
| Votes: | 0 |
Description
facter does not clean locale environment variables prior to executing commands and sometimes falls over the localized output. I’m not sure whether this is relevant for facter being executed by puppet, but it makes debugging a lot harder. For example with the macaddress fact
root@mail:~# facter | grep mac Could not retrieve macaddress: undefined method `split' for nil:NilClass Could not retrieve macaddress: undefined method `split' for nil:NilClass root@mail:~# LANG=C LC_ALL=C facter | grep mac macaddress => 52:54:00:94:f3:1c macaddress_eth0 => 52:54:00:94:f3:1c
The reason is that macaddress.rb is looking for ether or HWaddr
setcode do
ether = []
output = Facter::Util::Resolution.exec("/sbin/ifconfig -a")
output.each_line do |s|
ether.push($1) if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
end
Facter::Util::Macaddress.standardize(ether[0])
which is not contained in the localized output
root@mail:~# ifconfig -a
eth0 Link encap:Ethernet Hardware Adresse 52:54:00:94:f3:1c
inet Adresse:80.244.243.68 Bcast:80.244.243.71 Maske:255.255.255.248
inet6-Adresse: 2001:4d88:1005::25:1:2/64 Gültigkeitsbereich:Global
inet6-Adresse: fe80::5054:ff:fe94:f31c/64 Gültigkeitsbereich:Verbindung
UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1
RX packets:4018239 errors:0 dropped:0 overruns:0 frame:0
TX packets:790814 errors:0 dropped:0 overruns:0 carrier:0
Kollisionen:0 Sendewarteschlangenlänge:1000
RX bytes:658542927 (628.0 MiB) TX bytes:162143875 (154.6 MiB)
The full difference between a LANG=de_DE and LANG=C run on the same machine:
--- /tmp/facter.DE 2011-10-25 22:17:13.568013673 +0200 +++ /tmp/facter.C 2011-10-25 22:17:19.504013672 +0200 @@ -8,7 +8,11 @@ hostname => mail id => root interfaces => eth0,lo -ipaddress => 80.244.243.71 +ipaddress => 80.244.243.68 +ipaddress6 => 2001:4d88:1005::25:1:2 +ipaddress6_eth0 => 2001:4d88:1005::25:1:2 +ipaddress_eth0 => 80.244.243.68 +ipaddress_lo => 127.0.0.1 is_virtual => true kernel => Linux kernelmajversion => 3.0 @@ -19,9 +23,16 @@ lsbdistid => Debian lsbdistrelease => testing lsbmajdistrelease => testing +macaddress => 52:54:00:94:f3:1c +macaddress_eth0 => 52:54:00:94:f3:1c manufacturer => Bochs -memoryfree => 345.66 MB +memoryfree => 348.94 MB memorysize => 749.06 MB +netmask => 255.255.255.248 +netmask_eth0 => 255.255.255.248 +netmask_lo => 255.0.0.0 +network_eth0 => 80.244.243.64 +network_lo => 127.0.0.0 operatingsystem => Debian operatingsystemrelease => wheezy/sid osfamily => Debian @@ -45,5 +56,5 @@ uptime => 1 day uptime_days => 1 uptime_hours => 29 -uptime_seconds => 107884 +uptime_seconds => 107890 virtual => kvm
uptime_seconds and memory_* has to be ignored here of course.
facter should probably reset LANG/LC* variables or even better use a sane API, for example /sys/class/net/ethx/address on platforms where it is supported
Related issues
History
Updated by Ken Barber 7 months ago
- Category set to interface
- Status changed from Unreviewed to Accepted
- Keywords set to locale
Updated by Ken Barber 7 months ago
Also seen when parsing strange strings:
FACTER_foobar="Bob’s iMac" facter --yaml
But works with:
LANG=C FACTER_foobar="Bob’s iMac" facter --yaml
Updated by Michael Stahnke 7 months ago
- Target version set to 1.6.x
Updated by Ken Barber 4 months ago
- Status changed from Accepted to Needs More Information
Bernhard, I’m unable to replicate your ipaddress/macaddress failure myself. I’ve tried master, and even went back to version 1.6.0 and version 1.6.2 to see if I could replicate it:
[root@localhost facter]# pwd
/root/Development/facter
[root@localhost facter]# git status
# On branch master
nothing to commit (working directory clean)
[root@localhost facter]# export RUBYLIB=./lib
[root@localhost facter]# ./bin/facter | grep ipaddress
ipaddress => 192.168.182.158
ipaddress_eth0 => 192.168.182.158
ipaddress_lo => 127.0.0.1
[root@localhost facter]# ./bin/facter | grep macaddress
macaddress => 00:0C:29:08:95:C5
macaddress_eth0 => 00:0C:29:08:95:C5
[root@localhost facter]# echo $LANG
de_DE.UTF-8
[root@localhost facter]# git checkout 1.6.0
Note: checking out '1.6.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 23bb324... Readying for release of 1.6.0
[root@localhost facter]# ./bin/facter | grep macaddress
macaddress => 00:0C:29:08:95:C5
macaddress_eth0 => 00:0C:29:08:95:C5
[root@localhost facter]# ./bin/facter | grep ipaddress
ipaddress => 192.168.182.158
ipaddress_eth0 => 192.168.182.158
ipaddress_lo => 127.0.0.1
[root@localhost facter]#
I did this test on a German installed Centos 6.0 using Ruby 1.8.7. Can you give me more details of the exact platform this was occurring on? Or any other pointers on how to replicate this?