Getting rolling with Ansible on OSX 10.9.5

If you’re trying to leverage Ansible on OSX to control AWS instances with the API extension (and who isn’t these days 😛 ) and you get something like this back:

ansible-playbook -i inventory/ playbook.yml
Traceback (most recent call last):
File “/usr/local/bin/ansible-playbook”, line 28, in
import ansible.playbook
File “/Library/Python/2.7/site-packages/ansible/playbook/”, line 20, in
import ansible.runner
File “/Library/Python/2.7/site-packages/ansible/runner/”, line 32, in
import jinja2
File “/Library/Python/2.7/site-packages/jinja2/”, line 33, in
from jinja2.environment import Environment, Template
File “/Library/Python/2.7/site-packages/jinja2/”, line 13, in
from jinja2 import nodes
File “/Library/Python/2.7/site-packages/jinja2/”, line 18, in
from jinja2.utils import Markup
File “/Library/Python/2.7/site-packages/jinja2/”, line 520, in
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe

‘And boom goes the dynamite’

A few things:

Install Xcode from the App Store. This is key, run Xcode. Running if for the first time finished the install process.

Second, install from pip like this: sudo CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install ansible

Even if you’ve installed it with other method, such as homebrew, run the above command.

Get the and ec2.ini files from here: (note, you can get docker, vmware, nova, etc here too)

I didn’t have issues with ansible and my DigitalOcean vms running on CentOS 6.5, controlling a bunch of CentOS 6.5 machines. And, didn’t have issues with ansible on my Mac Pro (10.9.3) controlling my CentOS DigitalOcean VMs, but when I tried to use the API, things got ugly.

Honorable mention, do these things too because their needed or will save you headache.

put this in your ~/.bash_profile or ~/.bashrc

export AWS_ACCESS_KEY=your-aws-access-key-id
export AWS_SECRET_KEY=your-aws-secret-key

put this in your ~/.boto file (you need to make this file)
export AWS_ACCESS_KEY=your-aws-access-key-id
export AWS_SECRET_KEY=your-aws-secret-key

sudo pip install boto
sudo pip install pycrypto (this will blowup if you haven’t run Xcode at least once. If you plan to use the vault feature with Ansible, then you’ll need to upgrade the pycrpto 10.9.5 ships with)

I personally have lost a lot of time on digging around looking for Ansible OSX related answers. Hopefully this helps someone.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s