Ansible Inventory

    In Ansible, an inventory is a list of hosts or groups of hosts that Ansible can manage. The inventory is used to specify the hosts that Ansible will be executing commands or playbooks against.

    An inventory file can be created in various formats, such as INI, YAML, or JSON, and can contain information about hosts, groups, and variables. The inventory file can be stored locally or remotely and can be dynamically generated from a script or a database.

    Here's an example of an inventory file in INI format:


    In this example, we have two groups of hosts, "web" and "db", each with their own hosts and IP addresses. The "all:vars" section contains global variables that can be used across all hosts, such as the SSH user and private key file.

    Once you have created an inventory file, you can use it to run Ansible commands or playbooks against the specified hosts or groups. For example, to ping all hosts in the inventory file, you can use the following command:

    ansible all -m ping -i /path/to/inventory/file

    A basic INI ansible hosts file is located at /etc/ansible/hosts.