Ansible applies variable precedence from least to greatest: role defaults sit lowest, followed by inventory file or script group vars, inventory and playbook group_vars, inventory file or script host vars, inventory and playbook host_vars, host facts and cached set_facts, play vars, vars_prompt, vars_files, role vars, block vars, task vars, include_vars, registered vars and set_facts, role and include_role params, and include params; extra vars, passed with -e, always win. Command-line values such as -u my_user are not variables. In general, Ansible gives precedence to variables defined more recently, more actively, and with more explicit scope. Variables in a role's defaults folder are easily overridden, while anything in the role's vars directory overrides previous versions of that variable in the namespace; explicit includes such as include_vars tasks override inventory variables. Ansible merges variables set in inventory so more specific settings override more generic ones — for example, ansible_ssh_user set as a group_var is overridden by ansible_user set as a host_var. Within any section, redefining a var overrides the previous instance. Scope: Ansible. Reviewed October 4, 2026.
Understanding variable precedence
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- docs.ansible.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.