Interview Prep/Ansible/Variables, Facts and Precedence Problems

`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.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems