homeblogfacter 4 back to the roots

Facter 4: back to the roots

What is Facter?

Facter is a cross platform system profiling tool. It gathers nuggets of information about a system such as its hostname, IP address and operating system. We call these nuggets of information facts and they are used by other Puppet products like Puppet, Puppet Server and Bolt to make decisions in their automation process. You can extend Facter by writing custom facts or external facts and use them in Puppet manifests.

You’ll find this blog post useful when migrating from older versions of Puppet to Puppet 7. The new features allow a granular control and enable new use cases.

Facter 4

Starting with Puppet 7, Facter 4 is the default version of Facter.

Facter 4 is written in Ruby and provides many new capabilities that you didn’t have with Facter 3, including:

  • Blocking and caching all types of facts at a granular level
  • User-defined fact groups
  • Creating custom and external fact hierarchies using the dot notation
  • Profiling using the --timing command line option
  • Improved module testing

We explore these in more detail below. Note that while we aimed for 100% API compatibility with Facter 3, there may still be some small inconsistencies. One known example would be facter -p which was dropped in favor of puppet facts show. For more details, you can have a look over our release notes.

Blocking and caching any fact

Facter 4 allows blocking and caching any type of fact at a granular level. For example, if you block the memory fact, you won’t get any memory facts, but if you block the memory.swap fact, you will still get memory.system facts. The best part about the new blocking and caching mechanism is that you can go as deep as you want in the facts hierarchy — you can even block only the memory.swap.available fact.

memory fact example:

memory.swap blocked example:

To block and cache facts, and even groups of facts, use the blocklist and ttls attributes from facter.conf. In the example below, memory.swap is a fact and EC2 is a group consisting of two facts: ec2_metadata and ec2_userdata. The same principles apply for cached facts.

Blocking and caching groups

As we mentioned above, you can also block and cache groups of facts. Using the new fact-groups attribute in the facter.conf configuration file, you can place multiple facts in a group, and block or cache it. For example:

Custom and external facts hierarchy

You can arrange custom and external facts in hierarchical order using the . notation. Let's say you have the following two custom facts named my_organization.my_custom_fact1 and my_organization.my_custom_fact2. You can add an external fact named my_organization.my_external_fact, and the final output would be:

Fact profiling

Facter 4 revives the --time flag from Facter 2. Using this command line option, you can obtain benchmark information regarding facts.

Improve testing

Many modules still run their tests with Facter 2 because Facter 3 was never released as a Ruby gem. This discrepancy between the way modules were tested and how they were actually being used allowed some bugs to get past CI pipelines. Facter 4 is released as a gem, so you can safely test your modules with the exact same Facter version that is used in production environments.

Learn more