If you are not familiar dynamic inventory, check out Ansible - Getting Started with Dynamic Inventory.
This assumes you have the host_list plugin in ansible.cfg enabled, like this.
[inventory]
# enable inventory plugins, default: 'host_list', 'script', 'yaml', 'ini'
enable_plugins = host_list, yaml, ini
The ansible command with the --list-hosts and -vvv flags can be used to determine if the host_list plugin is being used.
AVOID TROUBLE
When targetting a single managed node, you must include a comma after the managed node hostname
When targetting two (or more) managed nodes, including a comma after the last managed node is optional
ansible all -i "server1.example.com," --list-hosts -vvv
If you get something like this, this suggests you did not define host_list in ansible.cfg properly.
[WARNING]: Unable to parse server1.example.com, server2.example.com as an inventory source
If the following is returned, the host_list plugin is being used.
Parsed server1.example.com, inventory source with host_list plugin
Something like this should be returned.
hosts (2):
server1.example.com
server2.example.com
Or, the ansible-inventory --list command can be used.
ansible-inventory -i "server1.example.com, server2.example.com" --list
Or, the ansible-inventory --graph command can be used.
ansible-inventory -i "server1.example.com, server2.example.com" --graph