Interview Prep/Ansible/Variables, Facts and Templates

A variable you set in `group_vars` is being overridden and you do not know where. How do you find the source?

IntermediateScenarioVariables, Facts and Templates
Answer

Situation read → Precedence conflict across up to 22 levels.

What I'd do →

  1. Print the final value: ansible web01 -m debug -a "var=app_port".
  2. Search the repo: grep -rn "app_port" ..
  3. Check the usual suspects: -e extra vars, set_fact, role vars/ (higher than group_vars), play vars:, and host_vars.
  4. Run with -vvv and look at where each var file loads.

Why → Role vars/main.yml, set_fact, include_vars and -e all outrank group_vars.

Interview tip → Say you keep tunable defaults in role defaults/ precisely because it has the lowest precedence.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Templates