An inventory specifies and describes all of the target devices (i.e. hosts) in the Ansible environment. The inventory can be either a single file or a series of files, written typically in INI or YAML format. Defined in the file(s) are variables that Ansible will use to communicate with and configure the target systems. The inventory can contain various hosts of different platforms, operating systems, and manufacturers. Ansible doesn't care about the nature of the devices in the inventory, only that the inventory is formatted accurately!
Ansible offers a default inventory with the file
/etc/ansible/hosts, which is used in Ansible Engine commands whenever an inventory is not explicitly specified. The location of the default inventory can be set by modifying the Ansible configuration file. While Ansible offers the choice to use the default inventory, it is preferable to explicitly supply a user-defined inventory by specifying the "-i" option in Ansible Engine commands.
It is not uncommon to see hundreds or even thousands of devices in a production environment. Keeping track of all their information can be difficult, so it is suggested that devices be logically organized into groups, or even groups of groups, in an inventory. Using groups and variable files will make inventory management less cumbersome and more workable. For a comprehensive tutorial on structuring and organizing your inventory, refer to How to build your inventory.
Below is an example of an inventory arrangement that features an INI inventory file "hosts," along with group and host variable files. The group variable files exist in the "group_vars" directory and the host variable files reside in the "host_vars" directory.
/etc/ansible | hosts | ... └───group_vars | | aoscx_switches.yml | | ... | └───host_vars | switch1.yml | switch2.yml | ...
[aoscx_switches] switch1 switch2
ansible_connection: httpapi # Do not change ansible_network_os: aoscx ansible_httpapi_validate_certs: False ansible_httpapi_use_ssl: True ansible_acx_no_proxy: True
Updated over 2 years ago