ansible-inventory
Display Ansible managed hosts and groups
TLDR
Display the default inventory
Display a custom inventory
Display the default inventory in YAML
Dump the default inventory to a file
SYNOPSIS
ansible-inventory [options] [host | group]
PARAMETERS
-h, --help
Show help message and exit.
--version
Show version information.
-v
Verbose mode (repeat for more verbosity).
--flush-cache
Clear inventory cache.
-i INVENTORY, --inventory INVENTORY
Inventory file, directory, or comma-separated list.
--list
List entire inventory (default if no host/group specified).
--host HOST
Output data for specific host.
--graph
Display inventory as a graph.
--vars
Include variable values in output.
--host-vars HOST
Variables for specific host.
--group-vars GROUP
Variables for specific group.
--types
Include data file type info.
--playbook-hosts HOST_PATTERN
Hosts matching pattern for playbook.
--playbook-groups GROUP_PATTERN
Groups matching pattern for playbook.
--metadata [TYPE]
Output metadata (host/group/plugin).
-y, --yaml
Output in YAML format.
--pretty
Pretty-print output.
--output FORMAT
Output format: text, json, yaml (default: text).
--playbook-path PLAYBOOK_PATH
Path to playbook for inventory context.
DESCRIPTION
The ansible-inventory command is a powerful tool within the Ansible automation platform used to parse, query, and display information from Ansible inventory files or dynamic inventory sources. It allows users to list hosts, groups, variables, and relationships in various formats like JSON, YAML, or graph visualizations.
An inventory in Ansible defines the managed nodes (hosts) and organizes them into groups, along with associated variables for configuration. ansible-inventory supports static inventory files (INI or YAML), dynamic inventories (scripts or plugins), and even constructed inventories. Common use cases include debugging inventory issues, generating documentation, integrating with CI/CD pipelines, or exporting data for other tools.
Key features include dumping the entire inventory structure (--list), querying specific hosts or groups (--host, --group-vars), viewing variable precedence, and rendering graphs (--graph) for visual representation. Output can be formatted for machine readability (JSON/YAML) or human-friendly pretty-printing. It respects Ansible's configuration files and respects cache mechanisms for performance.
This command is essential for inventory management in large-scale deployments, ensuring accuracy before running playbooks with ansible-playbook.
CAVEATS
Requires Ansible 2.4+; dynamic inventories need executable scripts/plugins; cache may need flushing for updates; large inventories can be slow without --pretty.
EXAMPLES
ansible-inventory --list
List all hosts/groups in JSON.
ansible-inventory --graph
Generate inventory graph.
ansible-inventory -i hosts.ini --host webserver --vars
Show variables for host.
HISTORY
Introduced in Ansible 1.0 as basic inventory parser; rewritten in Ansible 2.4 for plugin-based architecture; enhanced in 2.10+ with collection support and metadata output.
SEE ALSO
ansible(1), ansible-playbook(1), ansible-config(1)


