Ansible Server
- apt update (root user)
- apt install software-properties-common
- add-apt-repository — yes — update ppa:ansible/ansible
- apt install ansible
After installing, when you will check the /etc/ansible/ansible.cfg file you will only get this like:
So, run the following command:
- ansible-config init — disabled -t all > ansible.cfg
- vim /etc/ansible/hosts
Add the nodes IP which looks like this:
[Note: demo is a group (necessary but name could be anything)]
- vim /etc/ansible/ansible.cfg
Inside the ‘ansible.cfg’ file, you have to find one thing and add one thing:
find-> inventory and remove the ‘;’ which was in the start of inventory ( because ‘;’ used as # to uncomment).
add-> sudo_user = root, you can add anywhere around the previous inventory command.
- adduser ansible
- sudo passwd ansible
- visudo
Give the permissions to ansible user to perform any commands by adding the command:
Write the ansible line command
- ssh 172.31.84.64 (ansible user)
Then, you get this
So, it is showing you this error because you have configure the file /etc/ssh/sshd_configure, like in the below image:
- service start ssh/sshd
- ssh 172.31.84.64 (ansible user)
As you run this command, it will ask you the password of Node1. But when you enter in the
Node using SSH then, you can do anything such as creating a file or installing any package,
etc.
You can refer the below images:
But as you know, we need to enter the Node without asking for any password. So, to
do that follow the commands below:
- ssh-keygen (ansible user)
The file is present here,
Now, you have to copy this ssh key into both Nodes by the following commands:
- ssh-copy-id ansible@172.31.84.64 (ansible user)
- ssh-copy-id ansible@172.31.95.203 (ansible user)
So, the public key has been copied in the both nodes
- ssh 172.31.84.64 (ansible user)
- ssh 172.31.95.203 (ansible user)
This time, it won’t ask you for any password.
Another Demo for Node2
-> Ansible Server
-> Node 2
Node1
- apt update
- sudo su
- adduser ansible
- sudo passwd ansible
- service start ssh/sshd
- visudo (as root user)
Give the permissions to ansible user to perform any commands by adding the command:
Write the ansible line command
- configure the file /etc/ssh/sshd_configure, like in the below image:
- service start ssh/sshd
Node2
- apt update
- sudo su
- adduser ansible
- sudo passwd ansible
- service start ssh/sshd
- visudo
Give the permissions to ansible user to perform any commands by adding the command:
Write the ansible line command
- configure the file /etc/ssh/sshd_configure, like in the below image:
- service start ssh/sshd