| In facter 2.5, if a custom fact had a higher weight than a core fact, then the core fact was never resolved. For example:
$ cat /tmp/facts/ipaddress.rb |
Facter.add(:ipaddress, weight: 999) do |
setcode do |
$stderr.puts "resolved custom ipaddress fact" |
"127.0.0.1" |
end |
end |
$ bundle exec facter --version |
2.5.7 |
$ FACTERLIB=/tmp/facts strace -fi -e trace=execve bundle exec facter ipaddress |
.. |
[00007f22d18fe2fb] execve("/home/josh/.rbenv/versions/2.5.8/bin/bundle", ["bundle", "exec", "facter", "ipaddress"], 0x55d65f08b150 /* 66 vars */) = 0 |
[pid 2221958] [00007fa4525472fb] execve("/bin/uname", ["/bin/uname", "-s"], 0x555857ef11b0 /* 84 vars */) = 0 |
.. |
resolved custom ipaddress fact |
127.0.0.1
|
rspec-puppet relies on this "feature" so it can override core facts with a higher weight (999). However, in facter 4, the core fact is always resolved:
$ strace -fi -e trace=execve bundle exec facter --custom-dir /tmp/facts ipaddress 2>&1 |
... |
[pid 2226940] [00007fcf73acc2fb] execve("/usr/bin/head", ["head", "-1"], 0x55f5fea630d0 /* 66 vars */) = 0 |
[00007f63b89bb2fb] execve("/home/josh/.rbenv/versions/2.5.8/bin/bundle", ["bundle", "exec", "facter", "--custom-dir", "/tmp/facts", "ipaddress"], 0x56176a3ef010 /* 65 vars */) = 0 |
[pid 2226942] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "lo"], 0x559350170630 /* 83 vars */) = 0 |
[pid 2226946] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "enp0s31f6"], 0x5593500caab0 /* 83 vars */) = 0 |
[pid 2226950] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "wlp0s20f3"], 0x55934fe64320 /* 83 vars */) = 0 |
[pid 2226954] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "vmnet1"], 0x55934f0e4c00 /* 83 vars */) = 0 |
[pid 2226958] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "vmnet8"], 0x55934f0d9ff0 /* 83 vars */) = 0 |
[pid 2226962] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "docker0"], 0x55934f115a20 /* 83 vars */) = 0 |
[pid 2226966] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "ens1"], 0x55934f121e20 /* 83 vars */) = 0 |
[pid 2226970] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "tun0"], 0x5593502b8650 /* 83 vars */) = 0 |
[pid 2226974] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "lo"], 0x5593502d1220 /* 83 vars */) = 0 |
[pid 2226978] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "tun0"], 0x5593501156f0 /* 83 vars */) = 0 |
[pid 2226982] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "lo"], 0x559350313a70 /* 83 vars */) = 0 |
[pid 2226986] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show", "tun0"], 0x559350353fe0 /* 83 vars */) = 0 |
[pid 2226990] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "link", "show"], 0x5593503716e0 /* 83 vars */) = 0 |
[pid 2227002] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "route", "show"], 0x5593503bdfd0 /* 83 vars */) = 0 |
[pid 2227006] [00007f6257c3c2fb] execve("/sbin/ip", ["ip", "-6", "route", "show"], 0x559350123090 /* 83 vars */) = 0... |
resolved custom ipaddress fact |
127.0.0.1
|
The ip related commands are triggered when puppet's compiler trying to add server facts https://github.com/puppetlabs/puppet/blob/93c86d6dc8e9a0d84032e46b1d4c632df5254c00/lib/puppet/indirector/catalog/compiler.rb#L418. So this looks like a facter bug to me. I would think the core fact wouldn't be resolved if it's weight is less than an already resolved custom fact with a higher weight. But maybe that was done intentionally Bogdan Irimie Gheorghe Popescu? In any case, I'm going to move this to the FACT project. |