Ansible is shipped with Debian through the official repository. The Ansible version available through Debian repository is 1.7.
In this article let’s assume the following details for the machines
Server – Hostname: server, IP : 172.16.0.10
Node1 – Hostname: node1, IP : 172.16.0.11
Node2 – Hostname: node2, IP : 172.16.0.12
Ansible is available in Debian repository. Install Ansible using the following command.
apt-get install ansible
Generate ssh keypair on the Ansible server.
ssh-keygen
Do the following on nodes
Copy the public key of the server to all the nodes
cat .ssh/id_rsa.pub (On Server to copy public key)
Append the public key copied from the server to .ssh/authorized_keys file on all the nodes
Once the keys have been copied we can check them key using the following commands on the server.
# ssh root@node-1 . . # ssh root@node-x
The above command should login directly and not wait for a password.
Edit /etc/ansible/hosts and append the following lines
[nodes] node1 ansible_ssh_host=172.16.0.11 node2 ansible_ssh_host=172.16.0.12
Check the reachabilty of these nodes by using this following command
# ansible -m ping all
Ouput:
node2 | SUCCESS => { "changed": false, "ping": "pong" } node1 | SUCCESS => { "changed": false, "ping": "pong" }
We can use another command to check a particular node.
ansible -m raw -a 'df' node1
Ouput:
node1 | success | rc=0 >> Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 7736784 956916 6363820 14% / udev 10240 0 10240 0% /dev tmpfs 204876 4416 200460 3% /run tmpfs 512184 0 512184 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 512184 0 512184 0% /sys/fs/cgroup