puppetfacter

External custom fact not working on Puppet


I'm running Facter 3.6 and trying to add a custom fact. According to the documentation, the folder /etc/puppetlabs/facter/fact.d/ is automatically used for custom facts.

I place the following template into said folder as hello.rb:

Facter.add(:hello) do
  setcode do
    "Hello, world"
  end
end

I then force a puppet run on one of my agents with puppet agent -t.

When I look in PuppetDb I don't see my new custom fact hello. Did I miss a step in adding my external custom fact?


Solution

  • /etc/puppetlabs/facter/fact.d/ is the location for custom facts on the client nodes. If you want a custom fact to appear on only that client, then you can add the custom fact to that location. Pluginsync will also transfer your custom facts for the current catalog to that location automatically.

    Therefore, the preferred method for distributing custom facts is to place them inside the corresponding module's lib/facter directory. They will then be distributed to all nodes that have a catalog applied with that module in any of the module paths for its directory environment.

    Note specific documentation here: https://docs.puppet.com/facter/latest/custom_facts.html#using-the-ruby-load-path

    Also note you are doing a custom fact and not an external fact. If you were doing an external fact, then it would preferably be located in the corresponding module's facts.d directory: https://docs.puppet.com/facter/latest/custom_facts.html#fact-locations.