Search code examples
puppetpuppet-enterprisefacter

I want to execute my custom facts which I made it in facter


# hardware_platform.rb

Facter.add('hardware_platform') do
  setcode do
    Facter::Core::Execution.exec('/bin/uname --hardware-platform')
  end
end

I want to execute it and when I gave facter --puppet. This information is not coming in the facter log. Tell me how to get the information from facts


Solution

  • Facter offers multiple methods of loading facts:

    1. $LOAD_PATH, or the Ruby library load path
    2. The --custom-dir command line option
    3. 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.

    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
    

    Source: https://docs.puppet.com/facter/3.6/custom_facts.html#loading-custom-facts