After completing this section, you should be able to:
Manage hosts and host groups in inventories using a dynamic inventory.
Use the ansible-inventory command to validate data provided by dynamic inventories.
Ansible looks up host and host group information in an inventory. The names in the inventory are used by plays to determine on which hosts and host groups they should run. They are also used to determine the values of host variables and group variables, some of which might change how Ansible connects or authenticates to those managed hosts.
You have seen how to create and edit inventories as files, and how the ansible, ansible-inventory, and ansible-playbook commands locate inventory files.
You saw cases, for instance, where the -i option is used to have the ansible and ansible-* programs use a particular inventory file.
Supported formats for inventory files include INI and YAML.
# INI format - filename: inventory [servers] server1 server2 [leafs] leaf1 leaf2 [spines] spine1 spine2 [network:children] leafs spines
# YAML format - filename: inventory.yml
servers:
hosts:
server1:
server2:
spines:
hosts:
spine1:
spine2:
leafs:
hosts:
leaf1:
leaf2