Interview Prep/Ansible/Variables, Facts and Precedence Problems

`nginx_worker_processes` is `8` on one host, and nobody knows where it is set

IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → It is defined in one of more than 20 precedence layers: a role default, a role var, group_vars, host_vars, inventory, set_fact, include_vars, or extra vars.

Diagnose →

ansible-inventory -i inventories/prod --host web07 --vars | jq .nginx_worker_processes
grep -rn 'nginx_worker_processes' inventories/ roles/ playbooks/
ansible -i inventories/prod web07 -m ansible.builtin.debug -a var=nginx_worker_processes

If inventory does not have it, check set_fact, include_vars and the AWX extra vars and surveys.

Fix → Remove the stray definition, and keep the variable in one intended layer.

Prevent → Prefix role variables with the role name, keep overrides in group_vars only, and check for duplicate definitions in code review.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems