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 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
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.
Our inventory file is located on /etc/ansible/hosts by default
We need to add the IP Of our Both the Worker node machine here
Now when we run the # ansible all –list-hosts command then we can see that our manage node IP is reflecting here
We can also define the Hostname for the Worker node in the inventory file
Now when we run # ansible all –list-hosts command then we can see that our manage node hostname is reflecting here
We can also define the groups with the IP address in the inventory file
Now when we run # ansible all –list-hosts command then we can see that our manage node groups name is reflecting here
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
Here we defined the Worker-1-Machine & Worker-2-Machine IP
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
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
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
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.