Interview Prep/Ansible/Variables, Facts and Precedence

What are local (custom) facts?

IntermediateConceptVariables, Facts and Precedence
Answer

Files ending in .fact in /etc/ansible/facts.d/ on the target are read during fact gathering. They can be INI, JSON, or an executable that prints JSON. The data appears under ansible_local.

# /etc/ansible/facts.d/app.fact
[general]
version=1.4.2
role=api
- ansible.builtin.debug:
    msg: "App version is {{ ansible_local['app']['general']['version'] }}"

Handy for letting a host report its own deployed version, and for deploying with a different facts_path.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence