`Could not find or access 'prod.yml' Searched in: .../roles/app/vars/prod.yml ...` from `include_vars`
BeginnerTroubleshootingVariables, Facts and Precedence Problems
Answer
Likely causes → Relative paths in include_vars are resolved against the role's vars/ directory or the playbook's directory, not your current shell directory. The file may also be named after a value that does not exist ({{ env }}.yml with env unset or misspelled).
Diagnose → The error lists every path it searched. Compare them with where the file actually is.
Fix → Put the file in roles/app/vars/, or use "{{ playbook_dir }}/vars/{{ env }}.yml". For optional files, use the first_found lookup with a fallback:
- ansible.builtin.include_vars: "{{ lookup('ansible.builtin.first_found', params) }}"
vars:
params:
files: ["{{ env }}.yml", default.yml]
paths: ["{{ role_path }}/vars"]
Prevent → Validate env against an allowed list with assert before you use it in a path.
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