How on earth do you create a custom fact these days?

Problem:
I’ve been reading docs all day and am very confused how to get a custom_fact.rb to work with foreman.
I’m following the guide Custom facts overview - using the --custom-dir method but fail to see how to get it to work with foreman
Expected outcome:

Foreman and Proxy versions:
Foreman 3.3
Proxy 3.3
Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:

I use that like:

> $tree mymodule/lib/
> └── facter
>     └──custom_facts.rb
>

$cat mymodule/lib/facter/custom_facts.rb

> # encoding: UTF-8
> Facter.add('tallest_mountain') do 
>    setcode "echo Everest" 
> end

I assume from there just run puppet agent -t to deploy it to the rest of the foreman hosts?

You have to add the module to the hosts groups etc, then yes after puppet agent -t all hosts will have the custom fact

1 Like

Thanks a bunch.

One more question, is it suppose to report redundant puppet facts?

I use to get facts from RHSM (red hat logo), but after my custom facts module, I’m getting facts from puppet (P logo). Have you encountered the same thing as well?

Right, so I’ve since learnt that there are multiple ways to get facts, puppet/ansible/rhsm.
Is there no means of custom dynamic facts for RHSM since it’s already there, I don’t want to muddle it with other methods. AFAIK I can set a static custom_facts.fact in /etc/rhsm/facts in the client host.

This has two problems:

  1. It’s not dynamic, I want to check the content of a file in a client. Specifically see if a host has excluded something in yum.conf
  2. How would I deploy this to the rest of my hosts and future to-be-registered hosts?