Concept and mechanism
Inventory represents hosts and groups, including parent-child group relationships. A host with the same identity present in several groups should not be confused with distinct aliases for the same machine. Before changing systems, inspect hosts resolved by the pattern and limits used.
Configuration also has precedence: Ansible uses the first ansible.cfg found in its documented order and does not automatically combine every available file. Local configuration can therefore omit an option someone expected to inherit from /etc.
World-writable directories have a specific protection in automatic configuration discovery. Do not bypass it without understanding who can write there.
Guided application
In a fictional exercise, a batch group includes production and preproduction. Reducing forks only decreases concurrency; it does not correct inappropriate selection. Confirm effective variables too: a connection variable supplied as an extra var can override a lower-category command-line option.
In YAML, quote a value beginning with a Jinja expression while retaining the complete value. For registered loops, interpret the results list and each item rather than looking for one output summarizing every target. Use FQCN when the module collection must be explicit.
That identification resolves name ambiguity but does not install a missing execution-environment dependency.
Calculate the set before the window
In a fictional payment-batch exercise, apps contains pay_a, pay_b and pay_c; canary contains pay_a, pay_c and db_a; quarantine contains pay_c. Authorization covers canary applications outside quarantine. Before execution, write the expected list: pay_a only.
Compare it with ansible -i inventory/hosts.yml 'apps:&canary:!quarantine' --list-hosts. The lab confirms that result. Replacing intersection with union introduces pay_b and db_a even though the group names appear relevant.
Quote the pattern so the shell does not interpret its operators. At shift handover, supply the target list and the command that generated it. A group name does not freeze its members: a dynamic source may change between review and the window.
Revalidate the set, retain evidence and address differences from authorization before execution.
Distinguish selection, transport and result
Alias pay_a points to ansible_host=192.0.2.11. Listing the alias finds one machine; listing that address finds none because the address was not declared as an inventory name. Every address in this lab is demonstration data and no remote connection occurs.
The play uses hosts:apps. With --limit pay_a,db_a, only pay_a remains: the limit does not add db_a to the play. With --limit db_a, --list-hosts shows hosts (0) even though it exits zero.
A pipeline retaining only that code may approve an empty inspection. Add an acceptance criterion comparing the effective set with each play’s approved targets. A correct list also does not prove authentication, privileges or the ability to execute modules. Those checks belong to the next phase in an authorized environment.
Reproduce source resolution
The lab defines node in two synthetic sources. base.yml supplies batch_timeout=30 and service_config with port=8080 and retries=2. override.yml supplies batch_timeout=45 and service_config containing only port=9090. With base first, ansible-inventory resolves 45 and an object that no longer contains retries.
Reversing the sources resolves 30 and restores the complete base object. Lab configuration declares hash_behaviour=replace. For an application requiring both keys, the intended port alone is insufficient acceptance evidence.
Supply a complete object or make intended composition explicit and validate the result. Do not change global merge policy merely to hide an incomplete handover: assess effects on other consumers. Record source order alongside the code revision so another person can reproduce the same result.
Explain group conflicts
Another experiment places node in alpha and zeta, both direct children of all. alpha supplies timeout 20 and zeta supplies 60. Without special priorities, inspection returns 60. Declaring ansible_group_priority=50 in alpha variables inside the inventory source changes the result to 20.
Moving only that priority to group_vars/alpha.yml changes the result back to 60. Values and groups are the same; the stage at which priority becomes available has changed. Before mitigating an incident with extra vars, record competing definitions, group level and priority origin.
An override may be an authorized mitigation, but masks the cause if presented as the permanent correction. Avoid turning alphabetical group names into an undocumented implicit contract.
Inspect using the play context
The inventory/hosts.yml source has group_vars/apps.yml in its directory with timeout 30. The project contains project/site.yml and another group_vars/apps.yml with 75. Ordinary inventory inspection returns 30.
Adding --playbook-dir project returns 75; the play’s debug task also displays 75. This debug runs on the controller and does not demonstrate connection to the fictional address. When investigating a laptop/pipeline discrepancy, compare executable, play directory, sources, extra vars and environment.
Do not force 75 with -e merely to make the output look identical: that does not explain the origin used by the original execution. The experiment also shows forks=3 from the file and 7 when ANSIBLE_FORKS=7 is present. ansible-config dump --only-changed identifies the environment as the effective origin. Analyze concurrency configuration separately from target selection.
RUN handover exercise and summary
Before opening results, predict targets for four patterns and values for the two commands that reverse source order. Run the runner in a fresh directory using core 2.16.14 and compare commands.json with your predictions. Both recorded runs passed 20 checks across 18 invocations each.
Then introduce a controlled change to rehearsal data: add a host to canary and explain which earlier evidence is no longer sufficient. At RUN handover, provide revision, ordered source list, effective configuration, approved targets and required-variable comparison.
If selection does not match the request, suspend execution for that scope and resolve the discrepancy. Summarize learning in three questions: who was selected, which effective data did they receive, and what operation actually ran? Connect the answers to batches and handlers, role contracts, Git evidence and functional acceptance after change.
# Local rehearsal; listing commands do not execute remote modules
ansible -i inventory/hosts.yml 'apps:&canary:!quarantine' --list-hosts
ansible-playbook -i inventory/hosts.yml project/site.yml --limit db_a --list-hosts
ansible-inventory -i inventory/hosts.yml --host pay_a --playbook-dir project
ansible-config dump --only-changed-u operator and -e ansible_user=deploy are not equal votes: they belong to different precedence categories.
Common pitfalls
Forks as scope; configuration as universal merging; FQCN as installation.
Related topics: State and repeatability · Access and execution environment · Git, dev containers, and rehearsals
Compare effective targets and variables with the approved request; an error-free listing proves neither execution nor functional acceptance.
References
- Configuration and variable precedence · Current primary reference inspected 2026-09-30
- How to build your inventory · Current upstream reference; original controller experiment pinned to core 2.16.14
- Patterns: targeting hosts and groups · Current upstream reference; original controller experiment pinned to core 2.16.14