A collection of task oriented solutions in Puppet

 

Exclude facts from Facter

Challenge

You want to facter to skip certain facts

Solution

# Show the list of currently blockable
# fact groups

$ facter --list-block-groups

EC2
  - ec2_metadata
  - ec2_userdata
file system
  - mountpoints
  - filesystems
  - partitions
hypervisors
  - hypervisors
$ cat /etc/puppetlabs/facter/facter.conf
facts : {
  blocklist : [ "EC2" ],
}

Explanation

Facter can return a lot of details about your system, sometimes it can return a little too much, and take too long to do it. In those cases it can be useful to exclude certain facts from facter runs.

Introduced in the Facter 3 release series, the blocklist configuration setting for facter.conf (/etc/puppetlabs/facter/facter.conf by default) allows you to specify one or more fact groups that will then be completely skilled when facter runs. You can view the full list of available groups:

# Show the list of currently blockable
# fact groups

$ facter --list-block-groups

EC2
  - ec2_metadata
  - ec2_userdata
file system
  - mountpoints
  - filesystems
  - partitions
hypervisors
  - hypervisors

By adding those group names to the blocklist array they will be ignored by facter and neither fetched or made available to puppet. In one of my use cases I disable the EC2 facts when running within my own data centre.

$ cat /etc/puppetlabs/facter/facter.conf
facts : {
  blocklist : [ "EC2" ],
}

The configuration file requires double quotes ("), single quotes are silently skipped. It's early days for this feature and while the list of currently blockable facts is small hopefully as more uses are found it will be expanded and improved to allow arbitrary selection and skipping.

See also