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 all --list-hosts command will return the following.
~]$ ansible all --list-hosts [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' hosts (0):
To resolve this, you will need to define your inventory. Refer to Ansible - Defining your inventory. After you have defined your inventory, ansible all --list-hosts command should return your entire inventory. Or, you could use "unmanaged" or a custom inventory group. Refer to Ansible - Inventory groups (all | ungrouped | other).
ansible all --list-hosts
The -i command line option followed by an inventory file can be used to return the hosts from the specified inventory file.
ansible all -i /path/to/inventory/file --list-hosts
Something like this should be returned.
hosts (11): all: hosts: server1.example.com: server2.example.com: children: linux: server3.example.com: server4.example.com: windows: server5.example.com: server6.example.com:
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 all --list-hosts -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