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.
More on Variables, Facts and Precedence
Where can you define variables in Ansible?BeginnerHow do you reference a variable, and when must you quote it?BeginnerGive a summary of variable precedence.IntermediateWhat are the lowest and highest precedence sources, and why does that matter?IntermediateWhat is the difference between a role's `defaults/` and `vars/`?IntermediateWhat are facts and how are they gathered?Beginner