Installing Ansible via Git

Nov 25, 2014 • Jonathan Frappier

Please note these directions were based on Ansible 1.8. Please check Ansible documentation for updated information

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 python-devel

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://github.com/ansible/ansible.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;

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

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

NOW…..we have success

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.

Related Posts

In my last post on Ansible, the installation documentation walked us through a simple example of how to issue a command on a host by putting 127.0.0.1 in the inventory file. Now as you know 127.0.0.1 is that server itself; the real power of an automation tool is working on multiple systems. You can manage which systems Ansible runs commands or playbooks on (more on playbooks in a future posts) by putting them in an inventory file - and what’s really cool; Ansible does this all agentless!

A question came up on Twitter recently about how to add a stand-alone Hyper-V server as an endpoint. What I can gather from the documentation is that you need to have an agent deployed for Hyper-V but the directions were otherwise unclear so this is an attempt to document the required steps. First, the assumption is you have a Windows Server with the Hyper-V role at a minimum available (if you are running as a virtual machine; make sure the OS type is set to Hyper-V).