I extended a module (pdxcat/collectd) by calling it from my module. The base module prefers to identify Amazon Linux OSfamily as 'Redhat' but the facter installed by puppet on the Amazon Linux OS reports the os as 'Linux'.
I want to correct this bug by overwriting the facter value of osfamily from Linux to Redhat before calling the base module.
my osfamily.rb inside mymodule/lib/facter is
Facter.add('osfamily') do
setcode do
case Facter.value(:operatingsystem)
when "Amazon"
"RedHat"
else
Facter.value("kernel")
end
end
end
But the problem is, I am unable to overwrite the osfamily value. Even after loading facts from osfamily.rb, osfamily is still being reported as 'Linux' instead of 'Redhat'.
my code is working correctly for new values like osfamilytest
or operatingsystemreleasetest
but not for existing values like osfamily
or operatingsystemrelease
.
Puppet Version: 2.7.25
Facter Version: 1.6.18
Operating System:
Amazon Linux 2015.03
Puppet installation steps:
yum install puppet
I believe it is an anti-pattern to attempt to override built-in facter values for a community module. That said there are cases (like the above) where you should be able to override a fact given this is not a community module (e.g. internal).
If this is for an internal module, you should look at fact precedence - https://docs.puppetlabs.com/facter/3.0/custom_facts.html#fact-precedence
The way that Facter decides the issue of resolution precedence is the weight property. Once Facter rules out any resolutions that are excluded because of confine statements, the resolution with the highest weight is evaluated first. If that resolution returns nil, Facter moves on to the next resolution (by descending weight) until it gets a value for the fact.
By default, the weight of a fact is the number of confines for that resolution, so that more specific resolutions takes priority over less specific resolutions.
Give it a weight of 100 and see what fact resolution gives you.
Facter.add('osfamily') do
has_weight 100
setcode do
case Facter.value(:operatingsystem)
when "Amazon"
"RedHat"
else
Facter.value("kernel")
end
end
end