Introduction to Ansible Inventory
Ansible is a powerful IT automation tool that allows you to manage and configure multiple servers or hosts from a single control machine. At the heart of Ansible is the concept of an inventory, which is a list of the hosts that Ansible will manage.
The Ansible inventory can be defined in various formats, such as a simple text file, a dynamic script, or a cloud-based inventory source. The default inventory file is typically located at /etc/ansible/hosts
on the control machine.
The inventory file can be structured in different ways, such as grouping hosts by their function, location, or environment. This allows you to apply specific configurations or playbooks to specific groups of hosts.
Here's an example of a simple Ansible inventory file:
[webservers]
web01.example.com
web02.example.com
[databases]
db01.example.com
db02.example.com
[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=/path/to/your/key.pem
In this example, the inventory file defines two groups: webservers
and databases
. Each group contains two hosts. The [all:vars]
section sets global variables that apply to all hosts, such as the SSH user and the private key file.
By understanding the Ansible inventory, you can effectively manage and configure your infrastructure using Ansible.