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.
More on Variables, Facts and Precedence Problems
Variables in `group_vars/webservers.yml` are silently ignoredBeginnerYou set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`Intermediate`set_fact: release_tag=v2` runs, but later tasks still see `v1`Intermediate`'ansible.vars.hostvars.HostVarsVars object' has no attribute 'ansible_default_ipv4'` when templating `hostvars['db01']`Intermediate`'ansible_eth0' is undefined` on new cloud instancesBeginnerFacts like `ansible_hostname` became undefined after someone changed `ansible.cfg`Intermediate