Search code examples
puppetpuppet-enterprisefacter

In what order will facts found in files under a module/lib/facter/* be loaded on a puppet client?


I have the following file structure:

lib
└── facter
    ├── rackspace.rb
    ├── system_load.rb
    └── users.rb

I want to use a custom fact value found in system_load.rb (let's call this :system_me fact) in another custom fact that I am writing and defined in users.rb. Like this:

# users.rb

Facter.add('sogood') do
  you = ''
  me = Facter.value(:system_me)
  if me == 'foo'
    you = 'bar'
  end
  setcode do
    you
  end
end

However, I am worried on what happens if system_me fact value doesn't exist yet before client tries to run sogood.

So my question is:

  1. Are fact files like the one seen in the lib folder structure above loaded in alphabetical order of the filename (rackspace.rb -> system_load.rb -> users.rb) when I run puppet apply —facterpath=module/lib/facter ?

Solution

  • If a fact resolution attempts to obtain the Facter.value() for another fact that has not yet been loaded then Facter will immediately attempt to load the needed fact. That means that

    • No, fact files are not necessarily loaded in alphabetical order, but
    • you nevertheless should not need to worry about fact loading order.

    You do need to avoid creating dependency loops among facts, but custom facts relying on built-in facts will never cause such a loop.