LinuxCommandLibrary

ansible-inventory

Inspect and display inventory data

TLDR

List all hosts in inventory

$ ansible-inventory --list
copy
Show graph of inventory
$ ansible-inventory --graph
copy
Show host details
$ ansible-inventory --host [hostname]
copy
Use specific inventory
$ ansible-inventory -i [inventory.ini] --list
copy
Output in YAML format
$ ansible-inventory --list --yaml
copy
List hosts matching pattern
$ ansible-inventory --graph [webservers]
copy

SYNOPSIS

ansible-inventory [-i inventory] [--list|--graph|--host host]

DESCRIPTION

ansible-inventory inspects and displays Ansible inventory data. It shows how Ansible interprets your inventory, including dynamic inventories, group memberships, and host variables.
This tool is useful for debugging inventory configurations and understanding the effective inventory structure that Ansible will use.

PARAMETERS

--list

Output all hosts in JSON format
--graph
Output inventory as tree graph
--host hostname
Output variables for specific host
-i inventory
Inventory source
--yaml
Output in YAML format
--vars
Include host/group variables in output
--export
Output compatible with inventory plugins
-y
YAML output (shorthand for --yaml)
--playbook-dir path
Set playbook directory for relative paths

CONFIGURATION

/etc/ansible/hosts

Default inventory file listing managed hosts and groups.
/etc/ansible/ansible.cfg
System-wide Ansible configuration, including default inventory path.
~/.ansible.cfg
Per-user Ansible configuration overriding system defaults.
ansible.cfg
Project-level configuration in the current directory, highest priority.

CAVEATS

Dynamic inventories are evaluated when this command runs. Large inventories may produce extensive output. Variables shown are pre-evaluation (no Jinja2 templating).

HISTORY

ansible-inventory was introduced in Ansible 2.4 (2017) to provide better inventory inspection capabilities, replacing ad-hoc methods of debugging inventory issues.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community