Bug #12337

Can not use nest facts when writing custom facts

Added by Nan Liu 4 months ago. Updated about 1 month ago.

Status:Needs More Information Start date:01/31/2012
Priority:Normal Due date:
Assignee:Nan Liu % Done:

0%

Category:library
Target version:-
Keywords: Affected Facter version:
Branch:
Votes: 0

Description

This not only returns the wrong value, it also breaks osfamily:

Facter.add('my_osfamily')
  setcode do
    Facter.value(:osfamily)
  end
end

It’s as if operatingsystem doesn’t get loaded before it obtaining osfamily. It’s necessary for force loading before using a fact that depends on another fact to get the correct values: Actually this doesn’t work.

Facter.collection.loader.load(:operatingsystem)
Facter.collection.loader.load(:osfamily)

Related issues

related to Facter - Bug #11511: fact "architecture" picks up x86_64 rather than amd64 Merged - Pending Release 12/20/2011

History

Updated by Daniel Pittman 4 months ago

  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Daniel Pittman

This is part of a related suite of problems, in which it is actually super-hard to resolve facts well in the current model. This is not the first time that ordering and internal dependencies between facts have caused problems.

Ultimately, this needs a decision about the model: can we actually support interdependent facts at all, without going mad, or are we stuck forcing them to be unrelated to each other?

Updated by Nan Liu 4 months ago

  • Description updated (diff)

Updated by Nan Liu 4 months ago

Would moving osfamily fact to operating system fact and nesting it considered evil to work around this problem?

Updated by Ken Barber 3 months ago

Maybe I’m doing something wrong, but I can’t replicate this. Given a my_osfamily.rb file:

Facter.add('my_osfamily') do
  setcode do
    Facter.value(:osfamily)
  end
end

It works fine:

# ./bin/facter my_osfamily
RedHat
# ./bin/facter osfamily
RedHat

Is there something I’m missing here? Also:

irb(main):001:0> require 'facter'
=> true
irb(main):002:0> Facter["my_osfamily"].value
=> "RedHat"
irb(main):003:0> 

Updated by Stefan Schulte about 1 month ago

  • Status changed from Needs Decision to Needs More Information
  • Assignee changed from Daniel Pittman to Nan Liu

Facter in general allows dependent facts. It just doesn’t tell when it reaches a recursion and these recursions are not always easy to find.

I suspect the following: my_osfamily loads the osfamiliy fact in an earlier stage than before: osfamily now depends on operatingsystem. Operatingsystem on ubuntu relies on the lsbdistid fact. This fact can currently trigger recursions as described in https://github.com/puppetlabs/facter/pull/176. So it would be interesting what operatingsystem you are on and what “This not only returns the wrong value” actually means.

Also available in: Atom PDF