How to add a normal user in Inventory File in Ansible

Hello, everyone In this Article we are going to learn How to add a normal user in Inventory File in Ansible   in a very simple and easy step-by-step approach

Yellow Fishing Boat Blog Banner 60

If we execute the Ansible command on the Worker Machine server then the command will execute on the remote server with the root user by default.

In this scenario, we want to execute the command on the Worker Machine server using the Normal user that is defined on the Manage Node.

First we are creating the Normal user on the Worker Machine server machine and assigning the password for the User

Screenshot 2

Now we are making the Connection passwordless from the Controller Node Machine to the Manage Node Machine using ssh-keygen command

Screenshot 1 1

Now we are executing the # cd .ssh command in order to go inside the directory where the keys are stored.

Screenshot 4

From this directory, we are executing the following command in order to copy the keys to the Controller Machine

# ssh-copy-id devopstutuser@23.20.52.232
Screenshot 3

Now we can see that we can able to take ssh of the Manage Node machine from the Controller Machine

Screenshot 5

To achieve the task of How to add a normal user name for the Worker-1-Node machine. Soo there is a predefined variable that is present in the ansible that is called ansible_ssh_user.

Now we can assign the ansible_ssh_user value in the inventory file of the Controller-Machine for that user that we want to execute the ansible commands in the Worker-1-Node Machine.

Screenshot 7

Now we have defined the ansible_ssh_user=devopstut user in the Worker-1-Machine inventory file

Now when we execute the ansible command that will execute on the Worker-1-Machine with no root user the customized user that we created above On the Worker-1-Machine ie. devopstutuser the commands will execute on behalf of the devopstutuser now.

Screenshot 8

Conclusion

This is the complete knowledge of How to add a normal user in Inventory File in Ansible 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