← 返回命令列表

Linux command

ansible-inventory 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

List

ansible-inventory --list

Example

ansible-inventory --graph

Example

ansible-inventory --host [hostname]

Example

ansible-inventory -i [inventory.ini] --list

Example

ansible-inventory --list --yaml

Example

ansible-inventory --graph [webservers]

Export

ansible-inventory --list --export --output [inventory.json]

Example

ansible-inventory --list --toml

说明

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.

参数

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

FAQ

What is the ansible-inventory command used for?

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.

How do I run a basic ansible-inventory example?

Run `ansible-inventory --list` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --list do in ansible-inventory?

Output all hosts in JSON format