What Is Facter?
Facter is the tool that gathers information about a machine: operating system, IP addresses, memory, disks, virtualisation and much more. Puppet agents run Facter at the start of every run and send the result to the server, which uses it while building the catalog.
Facter Command
Common Core Facts
| Fact | Example value |
|---|---|
os.name | Ubuntu, Rocky, windows |
os.family | Debian, RedHat, windows |
os.release.full | 24.04 |
os.architecture | amd64, x86_64 |
kernel, kernelrelease | Linux, 6.8.0-45-generic |
networking.hostname, networking.fqdn, networking.domain | web01, web01.example.com |
networking.interfaces | Hash of interfaces with IP, MAC and netmask |
memory.system.total, memory.system.used | 7.77 GiB |
processors.count, processors.models | 4 |
mountpoints, partitions, disks | Storage information |
is_virtual, virtual | true, kvm, vmware, physical |
timezone, system_uptime | UTC, uptime hash |
path, ssh, selinux, ec2_metadata | More specific groups |
puppetversion, clientversion | Agent version |
Three Ways to Create Your Own Facts
| Method | Where it lives | Good for |
|---|---|---|
| Custom Ruby fact | lib/facter/name.rb in a module | Complex logic, reuse of Facter code |
| External fact: static | facts.d/*.yaml, .json, .txt on the node | Fixed values such as datacenter or owner |
| External fact: script | Executable in facts.d/ that prints key=value, JSON or YAML | Quick checks in Bash, Python, PowerShell |
Custom Ruby Fact
| Part | Meaning |
|---|---|
Facter.add(:name) | Defines a fact |
confine | Only resolve under this condition, otherwise skip |
setcode | Return the value (a string, number, boolean, array or hash) |
has_weight | If many resolutions exist, the highest weight with a non-nil result wins |
Facter.value(:x) | Read another fact |
Facter::Core::Execution | Safe way to run commands and find programs |
Test a Custom Fact
External Facts
External facts are the easiest option: no Ruby needed. Place files in the facts.d directory on the node.
'80' is not the number 80. Use YAML or JSON for real numbers and booleans, or convert in code with Integer($facts['x']).
Setting Facts at Provision Time
A common trick is to write a fact file during server creation (for example, via cloud-init or Terraform) to tell Puppet what role the server should have. A safer option for security-sensitive data is a certificate extension, which becomes a trusted fact.
Facts in Puppet Code and Hiera
Facter Caching and Blocking
Performance Tips
- Keep custom facts fast. A slow fact slows every agent run
- Avoid facts that call the network
- Do not return huge hashes, they inflate the catalog request and PuppetDB
- Block unneeded core facts with
facter.conf - Use
confineto skip on irrelevant systems
Practice Tasks
- Run
facterand find your IP address, memory and OS release using dot notation - Write an external YAML fact
datacenterand use it in a manifest - Write a Ruby custom fact that reports the number of logged-in users
- Create a structured fact (hash) and read a nested value in Puppet code
- Create
csr_attributes.yamlon a new lab VM, request a certificate and read$trusted['extensions']
Conclusion
Facter describes the node. Use core facts for decisions, external facts for simple data, Ruby facts for logic, and certificate extensions (trusted facts) for anything security related. Keep facts fast and small.

