Ansible Inventory file| Create Inventory File Root User

Hello, everyone In this Article we are going to learn How to make Inventory File the Root User in ansible  in a very simple and easy step-by-step approach

ansible inventory

Ansible Inventory File

When the ansible controller performs the task then they cannot directly connect to Worker Node IP.

The controller node will read their inventory file whatever information of the Worker node IP is written there the controller node performs that task.

We can mention the IP address of the Worker node or we can mention hostname or we can mention username and password for the Worke node in the controller node inventory file

How to check the location for the inventory File – Firest we need to check the location for the configuration file we need to ansible command with –version option.

# ansible --veriosn
Screenshot 1 18

Now we can see that our configuration file in /etc/ansible/ansible.cfg location when we view the content for this file we can get the location for our inventory file.

Screenshot 2 17

Our inventory file is located on /etc/ansible/hosts by default

Screenshot 4 17

We need to add the IP Of our Both the Worker node machine here

Screenshot 3 16

Now when we run the # ansible all –list-hosts command then we can see that our manage node IP is reflecting here

Screenshot 5 17

We can also define the Hostname for the Worker node in the inventory file

Screenshot 6 16

Now when we run # ansible all –list-hosts command then we can see that our manage node hostname is reflecting here

Screenshot 7 14

We can also define the groups with the IP address in the inventory file

Screenshot 8 14

Now when we run # ansible all –list-hosts command then we can see that our manage node groups name is reflecting here

Screenshot 9 14

How define the customized path in the inventory file

Now I want to create my own inventory file, not the default file provided by ansible the path of my inventory file is /custom-inventory-file. and we are creating the file name as custom_inventory here

Screenshot 10 13

Here we defined the Worker-1-Machine & Worker-2-Machine IP

Screenshot 11 15

Now we have to run an ansible command with -i option and the location for our custom inventory file in order to run the command with our customized inventory file

# ansible all --list-hosts -i /custom-inventory-file
Screenshot 12 14

Now We don’t want to define the path again and again with -i option in this scenario we need to change the default location of the inventory file to a customized location

We need to modify the /etc/ansible/ansible.cfg file to our customized location for the inventory file

Screenshot 13 12
Screenshot 14 9

Now we have to run # ansible all –list-hosts in order to view the content of the file we didn’t add the path with -i option still our command will works

Screenshot 15 9

Conclusion

This is the complete knowledge of how we create inventory file for the root user in ansible if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on the Linux post.

If you want to learn Ansible in the most simple language then please click on this link

If you want to learn Linux in the most simple language then please click on this link.

Leave a Comment