Skip to content
Latchkey

ansible-inventory: Usage & Common CI Errors

Inspect exactly which hosts and groups Ansible sees.

ansible-inventory shows the parsed inventory - hosts, groups, and variables - so you can debug static and dynamic sources before running a playbook against the wrong (or empty) set of hosts.

What it does

ansible-inventory parses an inventory source and renders it. --list emits the full inventory as JSON, --graph draws the group/host tree, and --host shows the variables for one host. It is the fastest way to confirm a dynamic inventory plugin (AWS EC2, GCP) actually returns hosts.

Common usage

Terminal
# Full inventory as JSON
ansible-inventory -i inventory.ini --list

# Human-readable group/host tree
ansible-inventory -i inventory_aws_ec2.yml --graph

# Show resolved vars for a single host
ansible-inventory -i inventory.ini --host web01

Common error in CI: dynamic inventory returns no hosts

A run does nothing because ansible-inventory --graph shows only "@all:" with no hosts, or errors "Failed to parse ... with auto plugin". The dynamic plugin lacks credentials/filters or the file is not enabled. Fix: confirm the plugin is enabled (enable_plugins in ansible.cfg), supply cloud credentials to the runner (e.g. AWS_REGION + role), and validate filters by running ansible-inventory --list first - never run a playbook against an inventory you have not confirmed is non-empty.

Key options

OptionPurpose
--listOutput full inventory as JSON
--graphShow the group/host tree
--host NAMEShow one host’s variables
-i SOURCEInventory file or plugin config
-yOutput in YAML instead of JSON

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →