Ansible - ansible-inventory --graph command

The ansible-inventory command with the --graph option can be used to display a graph of your inventory of managed hosts. Or, the ansible --list-hosts or ansible-inventory --list commands could be used as well.

Refer to Ansible - Getting Started with Inventory if you are unfamiliar with inventory.

After a clean install of Ansible, the default hosts file and inventory in the ansible.cfg file are commented out. With the default hosts file and inventory in the ansible.cfg file commented out, the ansible-inventory --graph command will return the following.

Also, the ansible-inventory command uses the YAML plugin to parse your default hosts file or your own inventory file. If your default hosts file or your own inventory file is using some other format, such as the INI format, the following will be returned.

[WARNING]:  * Failed to parse /etc/ansible/hosts with yaml plugin: YAML inventory has invalid structure, it should be a dictionary, got: <class
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available


The above error is commonly resolved be defining your inventory using the YAML file format, like this.



Be aware that if you do not use the -i command line option, the default hosts file will be used.

ansible-inventory --graph


The -i command line option followed by an inventory file can be used to return the hosts from the specified inventory file.

ansible-inventory -i /path/to/inventory/file --graph


Something like this should be returned.

  |  |
  |  |
  |  |
  |  |


Ansible uses different plugins to parse the default hosts file or your own inventory file, such as the host_list, yaml, or ini plugin. The -vvv flag can be used to determine the plugin that was used.

ansible-inventory --graph -vvv


In this example, the yaml plugin was used to parse the /etc/ansible/hosts file.

Parsed /etc/ansible/hosts inventory source with yaml plugin


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter e3b34 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |