Ansible configuration in Linux Step By Step

Ansible is a configuration management tool. To configure ansible in linux you must have installed ansible in your machine. In the following steps i will show you how to configure ansible in linux ubuntu centos rhel amazon aws ec2 machines. To configure ansible in Linux we need two machines one is ansible master machine and another one is client machine. in the following examples i will use as ansible master control machine and as client machine.

To install ansible in your master machine follow below articles.

Ansible configuration In Client Machine

Create User:

Create one user in client machine and assign password to that user. Here in my client machine i created the devops user.

Make This User As Sudo User:

To install any packages in client machine devops user must have sudo permissions. So assign sudo permissions with password less. To assign sudo permssions to any user we have to add that user in /etc/sudoers  file

vi /etc/sudoers 

add below line

Allow SSH From Master:

when you are executing any playbooks an client machine from master control machine. First ansible master machine will do ssh to client machine and then it will execute the tasks that you defined.

so allow port no 22 of client machine from master Ip address

in client security groups add this inbound rule

Allow user to connect with username/password

ansible will connect as devops user to client machine. so ansible master machine will do ssh to client like ssh devops@  So for that we have to allow devops user to connect from master machine with username and password.

Ansible configuration In master Control Machine:

in ansible master machine we have to generate ssh keys and share with client machine as devops user for that run below commands

after sharing ssh keys with client machine verify is your ssh working as expected or not by using below command.

ssh devops@

It will connect to your client machine. If it is connected then the configuration is successful and now you can run ansible playbooks.

Run Ansible Ad-Hoc Commands:

You can use anyone of the above commands to run ansible Ad-hoc commands.

Here -u or –user means ansible will connect to client machine as devops user.
Ansible master will do ssh to client machine like ssh devops@ and it will execute playbooks as devops user.

Run Ansible Playbooks:

To install any packages in linux we need root user or a user with sudo permissions. Here devops user is sudo user and the task will be executed as devops sudo user. Thats why we mentioned become yes.