Interview Prep/Ansible/Variables, Facts and Precedence Problems

You set `nginx_port: 8443` in inventory `group_vars`, but the role still uses `80`

IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → The role defines nginx_port in roles/nginx/vars/main.yml. Role vars/ are higher in precedence than inventory group_vars and host_vars. Only defaults/main.yml is lower.

Diagnose →

grep -rn 'nginx_port' roles/nginx/

Fix → Move tunable values to roles/nginx/defaults/main.yml. Keep vars/main.yml for internal constants that callers must never change, such as package names per OS.

Prevent → Use this convention in code review: anything a user may override goes in defaults/, prefixed with the role name.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems