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”

Ansible Inventory

See Also:

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

Old Entries:

inventory = /etc/ansible/hosts

New Entries:

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 server is define in both the groups.

Group Variables:
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.

[MySQL_servers] ansible_user=svcans ansible_port=2223 ansible_ssh_pass="redhat" ansible_connection=local ansible_connection=ssh

For more details, you can check ansible inventory documentation.

Enjoy it!

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.