While Facter's built-in facts are useful, it's actually quite easy to add your own facts. For example, if you have machines in different data centers or hosting providers, you could add a custom fact for this so that Puppet can determine whether any local settings need to be applied (for example, local DNS servers or network routes).
Creating custom facts
How to do it...
Here's an example of a simple custom fact:
- Create the modules/facts/lib/facter directory and then create the modules/facts/lib/facter/hello.rb file with the following contents:
Facter.add(:hello) do
setcode do
"Hello, world"
end
end
- Use puppet plugin to download the new fact definition:
[root@cookbook ~]...