Interview Prep/Ansible/Variables, Facts and Precedence Problems

A custom fact in `/etc/ansible/facts.d/app.fact` does not appear under `ansible_local`

IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes →

  • The file does not end in .fact.
  • The file is a static JSON or INI file but has the executable bit set, so Ansible tries to run it.
  • An executable fact prints something that is not JSON.
  • Facts were gathered before the task that created the file.

Diagnose →

ansible web01 -m setup -a 'filter=ansible_local'
ls -l /etc/ansible/facts.d/; /etc/ansible/facts.d/app.fact | jq .   # if executable

A broken file shows an error string under ansible_local.app instead of a dictionary.

Fix → Use mode: "0644" for static facts and "0755" for scripts that print JSON. After deploying the file, refresh facts with ansible.builtin.setup: filter=ansible_local.

Prevent → Ship custom facts in one role, together with a refresh task.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems