Dynamic Inventory
Cheat sheet · https://pcornel.dk/topic.php?topic=5396
Answer
Dynamic inventory derives hosts, groups and variables from a plugin, script or external system at runtime instead of relying only on a fixed host file.
Remember
- Dynamic ≠ real-time automatically; plugins can cache data or query eventually consistent APIs.
- API success ≠ complete inventory; filters, permissions and pagination can omit resources.
- Source object ≠ Ansible hostname directly; composition/keying can transform identity.
- Inventory refresh ≠ target reachable; discovery and execution are separate boundaries.
First checks
ansible-inventory -i netbox.yml --graph— NetBox pluginansible-inventory -i aws_ec2.yml --list— cloud pluginansible-doc -t inventory -l— available plugins
Verify in this order
source API → inventory plugin → groups/hostvars
Where it usually breaks
Dynamic inventory proves the configured discovery path returned a host model; it does not prove source completeness, freshness or target reachability.
Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification.
Dynamic Inventory Ansible boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5396