Loading custom facts
Facter offers multiple methods of loading facts.
These include:
-
$LOAD\_PATH, or the Ruby library load path. -
The
--custom-dircommand line option. -
The environment variable
FACTERLIB.
You can use these methods to do things like test files locally before distributing them, or you can arrange to have a specific set of facts available on certain machines.
On this page:
Using the Ruby load path
Facter searches all directories in the Ruby$LOAD_PATH variable for subdirectories
named Facter , and loads all Ruby files in those directories. If you had a directory in
your $LOAD_PATH like ~/lib/ruby, set up like this:
#~/lib/ruby
└── facter
├── rackspace.rb
├── system_load.rb
└── users.rb
Facter loads facter/system_load.rb, facter/users.rb, and facter/rackspace.rb.
Using the --custom-dir command line option
Facter can take multiple --custom-dir options on the command line that specifies a single
directory to search for custom facts. Facter attempts to
load all Ruby files in the specified directories. This
allows you to do something like this:
$ ls my_facts
system_load.rb
$ ls my_other_facts
users.rb
$ facter --custom-dir=./my_facts --custom-dir=./my_other_facts system_load users
system_load => 0.25
users => thomas,pat
Using the FACTERLIB environment variable
Facter also checks the environment variable FACTERLIB for a delimited (semicolon for Windows and colon for all other platforms) set of
directories, and tries to load all Ruby files in those
directories. This allows you to do something like
this:
$ ls my_facts
system_load.rb
$ ls my_other_facts
users.rb
$ export FACTERLIB="./my_facts:./my_other_facts"
$ facter system_load users
system_load => 0.25
users => thomas,pat
facter
-p with puppet facts show. The puppet facts show command is the default action for Puppet facts. Facter also
accepts puppet facts.