Use this when grouping hosts for targeting.
Groups
Inventory groups organize hosts by role, environment, site or platform, such as webservers or prod, so automation targets and variables apply to many hosts at once.
1. Groups organise hosts for targeting and variables.
2. Multiple dimensions (site, role, env).
3. Avoid deep nesting complexity.
4. Use keyed_groups from SoT.
5. Document.
hosts → groups → plays/vars
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as duplicate labels, stale inventory, conflicting authority, broad filters, race between read and write, orphaned relationships and automation acting on data not yet reconciled, choosing the cases most relevant to inventory grouping, group hierarchy, variable precedence and host membership identity instead of display-name assumptions.
Step 2 Common mistakes Narrow the fault
- Overlapping groups with conflicting variables.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Groups organize hosts by role, environment or site.
- Groups can be nested.
- Group variables apply to all members.
ansible-inventory --graph— group tree- Groups by role, site, environment — dimensions
- Nested groups — hierarchy
ReferenceWhy it matters1 section · depth on demand
What it is
Groups combine hosts by role, site or platform so playbooks and variables can target them.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Groups collect hosts that share properties — site, role, platform, environment — so automation can target them together and assign shared variables. Hosts can be in several groups, and groups can contain other groups.
all:
children:
site_oslo: { hosts: { sw-oslo-07: {}, rtr-oslo-01: {} } }
role_access: { hosts: { sw-oslo-07: {} } }
platform_ios: { children: { role_access: {} } }
ansible-playbook vlans.yml --limit 'site_oslo:&role_access' # intersection
ansible-playbook vlans.yml --limit 'role_access:!site_lab' # exclusion
When a variable is defined in several groups, precedence follows group depth and name order, which surprises people — keep each variable defined at one level where possible.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Inventory > Groups. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For inventory grouping, group hierarchy, variable precedence and host membership identity instead of display-name assumptions, prefer typed fields and stable IDs over human presentation text.