LOGBOOK

HELP

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=joe on the host line is a host variable for demo.example.com only. (ansible_user is a special connection variable: the account Ansible logs in as.)
  • The [servers:vars] section sets user=joe for every host in servers.

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:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026