Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Dynamic Inventory · Ansible

Direct 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.

When to use this

Use it when configuring, checking or troubleshooting Dynamic Inventory in Ansible.

First 30 seconds

1. Dynamic inventory pulls hosts from NetBox, cloud APIs, vCenter, etc.

2. Plugins with YAML config.

3. Group by tags/attributes (keyed_groups).

4. Cache for speed.

5. Credentials via env/vault.

Operational verification

source API → inventory plugin → groups/hostvars

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Ansible automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformAnsible automation · Dynamic Inventory owns runtime discovery into Ansible. External API/CMDB/cloud source correctness remains with those systems.
Scope / prerequisiteUse it when configuring, checking or troubleshooting Dynamic Inventory in Ansible.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

4 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

external source/API → auth/query/filter → plugin/cache → host/group composition → Ansible selection → target connection

Healthy evidence: source/query and cache semantics are known, returned host/group data matches expected scope, and representative target mapping is correct.

Step 2 Failure modes and next checks Narrow the fault

Suspicious evidence: stale cache, insufficient API permissions, hidden filters/pagination, changed naming composition or assuming discovery equals reachability.

Step 3 Common mistakes Narrow the fault
  • Slow dynamic inventory without caching.
  • Group names from tags that change unexpectedly.
Step 4 Where it fails Narrow the fault

Where Dynamic Inventory usually goes wrong: source authority, host/object identity, grouping/selection, staleness and downstream target resolution; provider/query identity, cache/staleness, stable host IDs and reproducible selection.

Evidence references

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.

observation · 1
Key points
  • 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.
Key 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
ReferenceWhat it is1 section · depth on demand

Core model

Trace source credentials/query, plugin configuration, returned data, cache behavior and transformation into Ansible hosts/groups before evaluating selection or connectivity.

ReferenceImportant terms & boundaries2 sections · depth on demand

What this shows and what it does not

Dynamic inventory shows the configured discovery path returned a host model, but it does not show source completeness, freshness or target reachability.

External API/CMDB/cloud source correctness remains with those systems.

In depth

A dynamic inventory builds the host list at runtime from an external source — NetBox, VMware, Proxmox, AWS, Azure — using an inventory plugin. Hosts, groups and variables then always match the source of truth.

# inventory/netbox.yml
plugin: netbox.netbox.nb_inventory
api_endpoint: https://netbox.example.com
group_by: [sites, device_roles, platforms]
query_filters:
  - status: active
export NETBOX_TOKEN=...
ansible-inventory -i inventory/netbox.yml --graph

Cache results for large sources (cache: true) and check the generated groups after source data changes.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docAnsible automation current

Authoritative/upstream documentation reviewed for bounded claims in Ansible > Dynamic Inventory. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
dynamic inventoryansible inventory plugincloud inventoryinventory discovery
Embedded reference data

Quick lookup tables

Dynamic Inventory Ansible boundary map

Fast input/selection, execution/result and target-proof boundaries for Dynamic Inventory.

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
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For Dynamic Inventory, rely on structured fields and stable IDs (source authority, host/object identity, grouping/selection, staleness and downstream target resolution; provider/query identity, cache/staleness, stable host IDs and reproducible selection) rather than text formatted for display.

Confirmation

Confirm action

Continue?