LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How do you set a variable for a parent group made of other groups in an INI inventory, and why is putting variables in the inventory file discouraged?

Define the parent with [servers:children] and give it [servers:vars]; every host in every child group gets the variable. It works, but it clutters the inventory, mixes hosts and variables in one file, and uses an older syntax. Prefer group_vars/ and host_vars/ files.

[servers1]
demo1.example.com
demo2.example.com

[servers2]
demo3.example.com
demo4.example.com

[servers:children]
servers1
servers2

[servers:vars]
user=joe

All four demo hosts get user=joe, because they are members of servers through its two child groups.

The drawbacks grow with the project: a real inventory has dozens of groups, and once each also carries a block of variables, the file no longer answers either question quickly ("which hosts are there?" or "what is set for this group?"). Splitting variables into one file per group or host keeps the inventory a plain list of machines, and lets you encrypt just the files that hold secrets.

Go deeper:

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