Quiz Entry - updated: 2026.11.05
What are custom facts, where do they live on a managed host, and how can they be written?
Custom (local) facts are values you define on the managed host itself. setup reads every file or script ending in .fact in /etc/ansible/facts.d/ and adds the result to the host's facts. They can be static INI or JSON files, or executable scripts that print JSON.
Why put facts on the host at all? Some knowledge belongs to the machine rather than to the inventory: which application release is installed, the host's role in a cluster, a licence key. Stored on the host, the value stays with the machine and any play that targets it can read it, for example to fill a configuration file or decide whether a task should run.
Rules:
- Location:
/etc/ansible/facts.d/on each managed host (the default). - File name: must end in
.fact, or it is ignored. - Static facts: an INI or JSON file. (YAML is not supported; JSON is the closest format.)
- Dynamic facts: an executable script that prints JSON to stdout. It must have the execute bit set, otherwise Ansible tries to read it as a static file.
Go deeper:
Adding custom facts: facts.d or local facts (official docs) โ static and executable
.factfiles.