I created a simple custom fact:
Facter.add(:hello) do
setcode do
"Hello, world"
end
end
and put it here (on puppetmaster):
/etc/puppet/modules/custom/lib/facter
I'm testing it on puppet client:
facter hello
and see nothing.
Whereas this command works (on puppet client):
facter --puppet hello
Hello, world
Checking if the fact is synced (on puppet client):
puppetd --test --pluginsync
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/hello.rb
info: Caching catalog for host.example.com
It looks like the custom fact is synced fine. I can't understand why it's not available via facter
.
Also, how can I use this new fact from puppetmaster? I need to build a simple conditional based on the custom fact.
For example, I added in site.pp
(on puppetmaster):
$string = "$hello"
notice("Testing custom fact: $string")
Again, in syslog there is no line from the notice
function.
I studied a lot of documentation and still can't get how to make it work.
I will appreciate if someone could look on this issue.
Thank you.
Configuration: Ubuntu Server 12.04, Puppet 2.7.11, facter 1.6.5
Best Answer
The custom facts from puppet are only used in puppet runs or when you use the
--puppet
flag onfacter
. If you're not ok with that, then put the custom facts somewhere that facter will always use - see here for details.The fact should be present for the catalog compile; you probably aren't logging notice messages. To use it as a condition: