An Introduction to Ansible Inventory Files
Generally you will be running the Ansible task on a large number of systems. So you need to store the system details in a file. This file is called Inventory file in Ansible. The default location of inventory file is /etc/ansible/hosts. In other words, Inventory managed the hostname in which we are going to deploy the Ansible script. Also If you want to use any other inventory file without changing the default inventory file you need to specify it during execution time -i “path of inventory file”
- WHAT IS ANSIBLE AND ITS ADVANTAGES?
- WHAT IS CHEF AUTOMATION TOOL AND IT’S FEATURES
- HOW TO CONNECT CHEF SERVER WITH NODES ON LINUX
- INSTALL AND CONFIGURE A CHEF WORKSTATION ON CENTOS/RHEL 7/6
- HOW TO INSTALL THE CHEF SERVER ON CENTOS/RHEL 5/6/7
- PUPPET VS. CHEF VS. ANSIBLE VS. SALTSTACK
Basic Inventory File:
# cat /etc/ansible/hosts
Also, If you want to change the default location of inventory file then you can modify it using Ansible configuration file.
# vim /etc/ansible/ansible.cfg
inventory = /etc/ansible/hosts
inventory = "Path of New Inventory File"
In inventory file you can also define multiple groups with a set of multiple system. Here we can also define single server in multiple groups. For eg:
Note: In above example apache3.techoism.com server is define in both the groups.
It is also possible to make groups of groups using :children suffix in Ansible inventory file.
Additional Variables in Inventory File:
You can also set value for many of the variables in Ansible inventory, so you can skip those variables in Ansible playbook.
mysql1.techoism.com ansible_user=svcans ansible_port=2223 ansible_ssh_pass="redhat"
mysql2.techoism.com ansible_connection=local ansible_connection=ssh
For more details, you can check ansible inventory documentation.