How to install Python packages to (Homebrew) Ansible’s site-packages folder

ansiblemac-osx

I have installed Ansible (v1.4.4) and Python (2.7.6) via Homebrew. I'm creating an Ansible playbook for setting up a local development machine on Mac (Mavericks). When I get to the step to import a MySQL database using the mysql_db module, Ansible complains "the python mysqldb module is required". So I installed it with pip (from Hombrew): pip install MySQL-python. After re-running, I get the same error message. The output of cat /usr/local/bin/ansible-playbook is

#!/bin/bash
PYTHONPATH="/usr/local/Cellar/ansible/1.4.4/libexec/lib/python2.7/site-packages" exec "/usr/local/Cellar/ansible/1.4.4/libexec/bin/ansible-playbook" "$@"

Installing with pip puts the packages in "/usr/local/lib/python2.7/site-packages", but Ansible has its own site-packages folder so the global packages don't interfere with what Ansible requires.
What's the best way to install to MySQL-python to Ansible's site-packages folder?

Best Answer

By default, Ansible will use the Python install at /usr/bin/python unless you tell it otherwise. If you want it to use Homebrew Python, just add this to your inventory file:

[local]
localhost ansible_python_interpreter=/usr/local/bin/python

Related Topic