# custom value of a structured fact item

hi,

since the stock 'networking' fact does not find the correct "primary" network interface in my case since there is another interface with the default route, i am trying to modify only the 'networking.ip' and 'networking.primary' value of this stuctured fact. Its straight-forward to replace the whole fact but how could i keep the stock values of the other items? As soon as i obtain the current value of the fact with

stock_fact = Facter.value(:networking)


the fact is resolved and there seems to be no way of modifying it afterwards.

edit retag close merge delete

You can add hashes, where keys in the second operand take higher precedence (override any values in the first operand).

( 2018-02-01 11:06:42 -0600 )edit

Sort by » oldest newest most voted

I think i don't get it. You mean the second operand of the Facter.value method like this?

Facter.add(:networking, { :value => "mynetworking" }) do
has_weight 200
setcode do
"does not matter whats here"
end
end


This sets "mynetworking" as value of the fact but if i retrieve the stock values before calling Facter.add, the stock fact code is evaluated and can not be modified later on. So with the following code i still end up with the stock values of the "networking" fact:

networking_fact_values = Facter.value(:networking)
Facter.add(:networking, { :value => "mynetworking" }) do
has_weight 200
setcode do
"does not matter whats here"
end
end

more