Use this when inventory is generated at runtime.
Dynamic Inventory · Inventory
Dynamic inventory generates the host list at runtime from a source like AWS, vSphere, Proxmox or NetBox using plugins, so automation always targets what actually exists.
1. Dynamic inventory queries SoT/cloud APIs.
2. Filters, keyed groups, compose vars.
3. Cache for speed.
4. Credentials via env/vault.
5. Validate output.
API → plugin → inventory
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
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 Common mistakes Narrow the fault
- Slow inventory queries on every run (enable caching).
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.
- Dynamic inventory is generated at runtime from a source.
- Plugins exist for cloud, vSphere and NetBox.
- Caching speeds up large inventories.
ansible-inventory -i netbox.yml --list | jq '._meta.hostvars | length'— NetBox dynamicansible-doc -t inventory netbox.netbox.nb_inventory— plugin docs- Cache settings — performance
ReferenceWhy it matters1 section · depth on demand
What it is
A dynamic inventory builds hosts and groups at runtime from a source such as NetBox, vCenter or a cloud API.
ReferenceImportant terms & boundaries2 sections · depth on demand
How it works
An inventory plugin queries the external system at the start of each run and turns its objects into hosts, groups (group_by, keyed_groups) and host variables (compose). Caching avoids repeating slow queries on every run.
Example
# netbox_inventory.yml
plugin: netbox.netbox.nb_inventory
api_endpoint: https://netbox.example.com
group_by: [sites, device_roles]
ansible-inventory -i netbox_inventory.yml --graph
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 > Dynamic Inventory. 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%