Starting with Ansible

By | 14th April 2015

This Blog post is about getting started with Ansible.

Getting started with Ansbile. If you haven’t started using Ansible then it is something you are missing.
Ansible is a configuration managemnt tool. It can be installed on any linux machine.

For this demo using ubuntu 12.04
It has some of the dependencies that need to be installed. Once installed you can check for ansible from the command line.
It uses ssh key to communicate with your machines. It does not have a master slave concept.


#sudo apt-get install ansible
Reading package lists… Done
>>

Once installed. Go to the following file and update the hosts on which you want to run it.
>>
# /etc/ansible/hosts.
#green.example.com
#blue.example.com
192.168.100.1
#127.0.0.1
>>

Running ansible test with a simple ping operation.

>>
root@ubuntu-12-04-1-x64:/etc/ansible# ansible all -m ping -vvvvv –ask-pass
SSH password:
ESTABLISH CONNECTION FOR USER: root
127.0.0.1 | FAILED => to use the ‘ssh’ connection type with passwords, you must install the sshpass program
>>

This means that you need to install sshpass.
Please note this might not be the best thing but can be used for test environment. This is only for DEMO.

Got the following issue. A one time ssh to the servers solved the issue.
>>
root@ubuntu-12-04-1-x64:~# ansible all -m ping –ask-pass -vvvvv
SSH password:
ESTABLISH CONNECTION FOR USER: root
EXEC [‘sshpass’, ‘-d6’, ‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘GSSAPIAuthentication=no’, ‘-o’, ‘PubkeyAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘192.168.100.1’, “/bin/sh -c ‘mkdir -p /tmp/ansible-1435802976.23-170519673763220 && echo /tmp/ansible-1435802976.23-170519673763220′”]
192.168.100.1 | FAILED => Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in “/tmp”. Failed command was: mkdir -p /tmp/ansible-1435802976.23-170519673763220 && echo /tmp/ansible-1435802976.23-170519673763220, exited with result 6
>>

It WORKS !!

>>
root@ubuntu-12-04-1-x64:~# ansible all -m ping –ask-pass -vvvvv
SSH password:
ESTABLISH CONNECTION FOR USER: root
EXEC [‘sshpass’, ‘-d6’, ‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘GSSAPIAuthentication=no’, ‘-o’, ‘PubkeyAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘192.168.100.1’, “/bin/sh -c ‘mkdir -p /tmp/ansible-1435803906.08-59489574138520 && echo /tmp/ansible-1435803906.08-59489574138520′”]
REMOTE_MODULE ping
PUT /tmp/tmpZrdI_U TO /tmp/ansible-1435803906.08-59489574138520/ping
PUT /tmp/tmp7cR1TX TO /tmp/ansible-1435803906.08-59489574138520/arguments
EXEC [‘sshpass’, ‘-d6’, ‘ssh’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘GSSAPIAuthentication=no’, ‘-o’, ‘PubkeyAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘192.168.100.1’, “/bin/sh -c ‘/usr/bin/python /tmp/ansible-1435803906.08-59489574138520/ping /tmp/ansible-1435803906.08-59489574138520/arguments; rm -rf /tmp/ansible-1435803906.08-59489574138520/ >/dev/null 2>&1′”]
192.168.100.1 | success >> {
“changed”: false,
“ping”: “pong”
}

>>
###########################

Hopefully I can return with better examples and playbooks.