Installing Ansible via Git

Jonathan Frappier Virtxpert

I’ll admit, Git is a completely foreign language to me but it is something I am going to need to learn.  In an attempt to do that, I am going to take something I sort of know how to do manually-ish – install Ansible, but this time install it via git.  Once this is wrapped up I am going to catch up on Matthew Brender’s Git #vBrownBag which he did as part of the DevOps series.  Hopefully this post, if nothing else, can help you get Ansible setup and running.  Now Ansible is fairly well documented, but like most open source projects I find they assume a bit to much in their documentation to get you completely up and running.  For example you might have trouble following getting everything needed to install by following their directions.

To start, you’ll need a linux box to use, I have a CentOS 6.4 setup already so I will be using that.  To get started, we will need git and Python on our linux box – pretty easy to do (When prompted, press y to install the various packages needed):

yum install git

Ansible also requires Python, so now to install Python

yum install python python-setuptools

Almost there, just a few more things Ansible needs get up and running.  Since python-setuptools is installed you can setup pip using a python tool called easy_install, then pip to install the others

sudo easy_install pip

Now that pip is installed (there is no yum package I could find for this)

sudo pip install paramiko PyYAML Jinja2 httplib2

Now that Python is installed we can move on to installing Ansible.  This is where we will start to use git, from / run

git clone git:// --recursive

With Ansible now cloned, its time to setup the environment which Ansible was nice enough to provide a script for; cd to /ansible and run:

source ./hacking/env-setup

By default, Ansible will look for an inventory file in /etc/ansible/hosts but the clone process or env-setup does not create that for us so;

mkdir /etc/ansible && touch /etc/ansible/hosts && echo "" > /etc/ansible/hosts

Now we have a host file which is where we will store all the systems we want to manage with Ansible and added our localhost IP to the file.  Next up you should be able to run a command, the documentation suggests

ansible all -m ping --ask-pass

But as you can see we are still missing something, a package called sshpass


We need just a couple more packages to complete this test example assuming you are on a clean install of CentOS

yum install wget
rpm -Uvh sshpass-1.05-1.el6.x86_64.rpm


ssh -l root

Accept the certificate, enter the password for your root user and log out

NOW…..we have success

Ansible working test

Ansible working test

Now that we have Ansible setup and working, it’s time to go back and review the #vBrownBag Jeff Geerling (@geerlingguy) did on it to take it to the next level. My next goal is to create a simple inventory file to perform tasks on multiple systems.

Installing Ansible via Git