Javatpoint Logo
Javatpoint Logo

Puppet Facter & Facts

In Puppet, we can put several values as an environment variable with the help of a facter. Facter is a tool of puppet, which is used to keep the environment level variable. It is exactly like an environment variable of Bash or Linux. Sometimes the information that is stored in facts and the machine's environment variable may overlap.

The key-value pair of the puppet is called as fact. Each resource has its own facts, and we can construct custom facts in Puppet.


This command lists all the different environment variables and their related values.

Puppet Facter and Facts

If you want to see only one variable, use the following command:


Puppet Facter and Facts

The main feature of facter and facts in puppet is that these are available throughout puppet code as "global variable", which means we can use it in any part of our code as per our requirement.

In puppet, three types of fact can be used:

  • Core Facts
  • Custom Facts
  • External Facts

Core Facts

At the top level, the core facts are described and available to everyone at any point in the code. List of some basic core facts are:

Core Facts
Modern Facts Legacy Facts
cloud legacy
disks bios_version
facterversion domain
identity fqdn
gce hostname
memory id
os ipaddress
path interfaces
ruby macaddress
virtual netmask
networking system32
partitions memorysize
processors memoryfree
kernelversion uuid

To see the full list of facts and values use the following command:

Puppet Facter and Facts
Puppet Facter and Facts

Custom Facts

We can also add the custom facts to the node in the following ways:

  • Using the "export FACTER ... Syntax"


Puppet Facter and Facts
Puppet Facter and Facts
  • Using the $LOAD_PATH settings

In Ruby, $LOAD_PATH is similar to the Bash $PATH variable, but it is not an environment variable; instead, it is a pre-defined variable.

In $LOAD_PATH "$" variable is an array to search and load the values.

Puppet Facter and Facts

Now, create a directory facter, add a .pp file and append the content to it:

Add the following content to the custom_facts.rb file:

Facter scans through the entire folder listed in $LOAD_PATH, and search for a directory called facter. Once it gets that particular directory, it will put them anywhere in the directory structure. If this folder is found, then it searches for any Ruby file in that facter directory and loads all the specified facts in the memory.


FACTERLIB is similar to $LOAD_PATH. There is only one difference in both, i.e., FACTERLIB is an OS-level environment parameter, and $LOAD_PATH is a Ruby special variable.

The environment variable may not be configured by default. Let's check:

Puppet Facter and Facts

To test the FACTERLIB, use the following steps:

Create a directory named test_facts.

Puppet Facter and Facts
Puppet Facter and Facts

To see the directory structure execute the following command:

Puppet Facter and Facts

Copy the following contents to the .rb files:

Puppet Facter and Facts

Puppet Facter and Facts

Now, use the export statement:

Puppet Facter and Facts

Now, test the new facter:

Puppet Facter and Facts

External Facts

If you want to apply some new facts created at the provisioning stage, then you can use external facts. External facts are the best way to apply metadata to a virtual machine (VM) at its provisioning time. For example, OpenStack, vSphere, AWS, etc.

Puppet can use all of the metadata and its generated information to decide what items should be included in the catalog that will be applied.

Next TopicPuppet File Server

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA