Quiz Entry - updated: 2026.11.05
What is the difference between host variables and group variables, and which wins if both set the same name?
A host variable applies to one host; a group variable applies to every host in a group (or in a group of groups). The host variable wins over the group variable, and a variable defined in the playbook wins over both.
In an INI inventory they can be written inline:
[servers]
demo.example.com ansible_user=joe
[servers:vars]
user=joe
ansible_user=joeon the host line is a host variable fordemo.example.comonly. (ansible_useris a special connection variable: the account Ansible logs in as.)- The
[servers:vars]section setsuser=joefor every host inservers.
The precedence makes sense from specificity: a group variable is a default for many machines, a host variable is a deliberate exception for one. If the exception lost, you could never override a group default for a single special server.
Go deeper:
How to build your inventory: assigning a variable to one machine / to many machines (official docs) โ host and group variables in INI and YAML inventories.