If you’re trying to leverage Ansible on OSX to control AWS instances with the ec2.py API extension (and who isn’t these days 😛 ) and you get something like this back:
ansible-playbook -i inventory/ec2.py playbook.yml
Traceback (most recent call last):
File “/usr/local/bin/ansible-playbook”, line 28, in
File “/Library/Python/2.7/site-packages/ansible/playbook/__init__.py”, line 20, in
File “/Library/Python/2.7/site-packages/ansible/runner/__init__.py”, line 32, in
File “/Library/Python/2.7/site-packages/jinja2/__init__.py”, line 33, in
from jinja2.environment import Environment, Template
File “/Library/Python/2.7/site-packages/jinja2/environment.py”, line 13, in
from jinja2 import nodes
File “/Library/Python/2.7/site-packages/jinja2/nodes.py”, line 18, in
from jinja2.utils import Markup
File “/Library/Python/2.7/site-packages/jinja2/utils.py”, 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 ec2.py and ec2.ini files from here: https://github.com/ansible/ansible/tree/devel/plugins/inventory (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 ec2.py 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
put this in your ~/.boto file (you need to make this file)
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.