Pcornel
Automation · Ansible

Dynamic Inventory

Cheat sheet · https://pcornel.dk/topic.php?topic=5396

Back to the Topic

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 plugin
  • ansible-inventory -i aws_ec2.yml --list — cloud plugin
  • ansible-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

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen 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

Confirmation

Confirm action

Continue?