`could not locate file in lookup: /etc/app/settings.json`
IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer
Likely causes → Lookups (file, template, env, pipe) always run on the controller. The file exists on the remote host, not on the machine running Ansible.
Fix → Read remote files with a module:
- ansible.builtin.slurp:
src: /etc/app/settings.json
register: raw
- ansible.builtin.set_fact:
settings: "{{ raw.content | b64decode | from_json }}"
Use ansible.builtin.fetch to copy the file back to the controller.
Prevent → Remember the rule: lookups and filters run locally, modules run remotely. The same applies to lookup('env', 'HOME'), which returns the controller's environment.
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