Use this when checking inventory before running jobs.
Inventory Validation
Inventory validation checks that hosts are reachable, names and addresses are unique, required variables are set and groups are correct before automation runs against them.
1. Validate inventory: required variables, types, uniqueness, reachability.
2. Run in CI.
3. Fail on errors.
4. Report unreachable hosts.
5. Fix in SoT.
inventory → validation → report
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
ansible-inventory --listPrimary Commands
Configuration and operational commands for this Topic.
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 Known-good, broken and when it is fixed Verify boundary
Known-good requires deterministic resolution of the intended target set, no unexpected duplicates, required variables present with expected types/values and a bounded dry-run/read-only query reaching the same objects. Passing syntax validation shows format only; resolved inventory identity and target reachability close the pre-execution boundary.
Step 2 Command read-back and what it shows Verify boundary
ansible-inventory --list is the bounded verification surface selected for Inventory → Inventory Validation. A known-good result is each expected target resolves once with the intended groups, connection identity and critical variables, and a bounded downstream connectivity/read-only task reaches the same target. Treat targets are missing/duplicated, unexpected groups or hostvars win precedence, stale plugin data is present, or downstream execution reaches a different endpoint as broken/suspicious. ansible-inventory --list shows controller-side resolved inventory at execution time, but it does not show network reachability, credentials or managed-node convergence.
Step 3 Common mistakes Narrow the fault
- Inventory without validation of required fields.
Step 4 Native failure isolation and next-check logic Narrow the fault
Resolve the exact inventory as the automation engine sees it and compare target count, identities, groups and critical variables with the authoritative source. If hosts are missing or duplicated, inspect discovery/filtering and normalization. If the target set is correct but variables are wrong, trace precedence/merge order and environment-specific overrides before editing task logic.
Step 5 Observation-driven branch and next-check logic Narrow the fault
For a failing Inventory → Inventory Validation case, freeze scope first: target/object, desired revision or request, and failure time. Inspect ansible-inventory --list. Branch on evidence rather than labels: if the target is absent or duplicated, inspect source filters and identity keys; if membership is correct but variables resolve unexpectedly, inspect group/host precedence and plugin data; if inventory is correct but execution fails, move to transport/authentication/target state.
- Check reachability before running jobs.
- Names and addresses must be unique.
- Required variables must be set.
- Inventory validation script (required vars, reachability) — checks
ansible all -m ping— reachability- Schema check of host vars — types
ReferenceHow it works3 sections · depth on demand
How it works
How it works: Ansible resolves inventory/group/host variables, renders task/module arguments, establishes the connection/become context, executes modules on the selected target and reports changed/ok/failed.
How it works
Inventory validation checks that automation targets, groups, variables and identifiers are complete, unique and internally consistent before execution. Static/dynamic inventory can be syntactically valid while resolving to the wrong hosts or stale attributes. The resolved execution set is the operational object; source file/API success alone is not enough.
How it works
In Inventory → Inventory Validation, effective state is split across inventory source parsing, host/group membership, variable precedence and the resolved endpoint identity passed to later automation stages. Dynamic and static inventory plugins produce a resolved graph of hosts, groups and hostvars; later playbooks consume this graph, so validation must check identity and precedence rather than only parser success. Plugin credentials, source API freshness, DNS, duplicate identifiers and secrets outside inventory are separate things to check. This matters because valid JSON/YAML inventory can still omit a target or assign the wrong connection variables, while a host present in inventory can still be unreachable.
ReferenceImportant terms & boundaries1 section · depth on demand
Method
Inventory validation checks the automation inventory before jobs run, so automation never targets wrong, missing or decommissioned systems.
1. Validate structure: every host has required variables (IP, platform, site, role).
2. Validate values: IP format, platform in the supported list, unique names and IPs.
3. Compare with the source of truth: no hosts missing, none extra.
4. Test reachability for a sample or all hosts.
5. Fail the pipeline on errors; report warnings.
ansible-inventory -i inventory/ --list > inv.json
python validate_inventory.py inv.json --schema schemas/host.json
| Check | Catches |
|---|---|
| Duplicate IPs | Copy-paste mistakes |
| Status = decommissioned | Jobs against retired devices |
| Unknown platform | Wrong driver selection |
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 > Inventory Validation. 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%