Inventory defines the list of the hosts that we are going to manage. We can group them logically in certain roles. For example, we would want to group our web servers in one group and application servers in another. A group can have multiple servers and one server can be a part of multiple groups.
It is also possible to have a group of groups by using :children suffix. Variables like the user which will be sued to execute the playbook commands can be defined for hosts as well.
Name of group is enclosed in square brackets . Server names can be their dns names or ip addresses.
[webservers] server1 [application] server1 server2 ansible_user=aditya [cluster:children] webservers application
The path to default inventory file is defined in Ansible configuration
/etc/ansible/ansible.cfg but it is possible to use any file as inventory by passing flag
-i to the ansible command. For dynamic environments like EC2, there are plugins and modules to generate inventory dynamically.