Inventory file in Ansible

Ansible Inventory File   |Ansible works against large no of systems   in your infrastructure at a same time.

You need to specify the details of these systems in some file.This file is called Ansible Inventory File .

By default the inventory file is located at /etc/ansible/hosts .To use other inventory file  we have to mention -i <path of inventory file> option at the time of execution .
You can change the default inventory file in the ansible configuration file.The default ansible configuration file located at /etc/ansible/ansible.cfg in which you can add or modify the variable to the newpath.

How to create basic inventory file

testnode1  ssh_user=root
testnode2  ssh_user=root

From the above example test node1 is the hostname of one remote machine.
By default ansible control machine connects to the remote node through ssh therefore ssh_user gives the ssh login name.Instead of the hostname of the remote server you can use ip address of the remote host also.
NOTE:If you not mention the ssh_user parameter ansible uses the same username from where you are going to run the script.

How to create Inventory file along with Groups

You can also create group using a set of systems in the ansible inventory file.This is required when you want to run a particular job for some systems and other job for other systems.
Here is the example like this.
[webserver]
Websvr1
websvr2

[dbserver]
Dbsvr1

In the above example webserver and dbserver are the group name which is defined in the square bracket.

Inventory file in Ansible,Ansible Inventory File
Ansible Inventory File


When you want to add a file to all systems you need not have separate group you can do like this .
[server:children]
webserver
dbserver

If this article is helpful to know about Ansible Inventory File please share this article.
SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment