Installing Ansible on OSX Lion

We’re currently evaluating configuration management (devops) tools at CATN to help us deploy and manage our new vCluster hosting platform in a production environment. Many of the tools we have looked at are fairly complicated, with a steep learning curve.

Then we came across, Ansible. It’s developed primarily by the guy who wrote Cobbler (our previous favourite deployment tool), and it’s been built from scratch to be much simpler to use.

Although it only took me just a few minutes to get it up and running, there were a couple of dependencies required to install it on OSX, so I thought I would document the steps here in case it helps someone else in the future:

Step 1 – Install Dependencies

Check that you have Xcode installed with , try typing gcc -v from the command line. If it says command not found, then ensure you have downloaded Xcode from App Store, then once it’s installed go to Xcode > Preferences > Downloads  and install the Command Line Tools.

Install pre-requisite Python modules on your main OSX machine that will be running ansible.

sudo easy_install jinja2
sudo easy_install PyYAML
sudo easy_install paramiko

If you get an error saying configure: error: no acceptable C compiler found in $PATH then you should double check you have Xcode and it’s command line tools as per the instructions above.

And on the managed nodes, assuming it’s a Centos/SL/RedHat node:

yum install python-simplejson

Step 2 – Checkout latest version of Ansible

Download the latest version from Github. Assuming you are installing into ~/github

cd ~/github
git clone git://github.com/ansible/ansible.git
cd ./ansible
source ./hacking/env-setup

Set up your bash profile to load the environment variables when you load a terminal

# Setup Ansible
cd ~/github/ansible
source ./hacking/env-setup
cd ~
export ANSIBLE_HOSTS=~/ansible_hosts
# End Ansible Setup

If you wanted to install it properly, rather than run the latest code from checkout you could do so with sudo make install. In this case you wouldn’t need to run the hacking/env-setup script to modify the environment variables, since ansible would be located within the ordinary search paths.

Step 3 – Test it works

Add some hosts to your ansible_hosts file, and then ping them.

echo "192.168.0.62" >> ~/ansible_hosts
ansible all -m ping