Multiple Ansible versions on Mac

Posted on Thu 03 March 2016 in SysAdmin

I ran into some regression bugs with the latest version of Ansible and wanted to test to confirm a few things before posting bug reports. As I run MacOS at work, Ansible is installed from Brew. If you're lucky, you might still have your old versions around:

$ ls /usr/local/Cellar/ansible/

Otherwise you can just clone the branch:

git clone -b ${VERSION} --recursive ${VERSION}

and run with the correct PYTHONPATH:

source ${ANSIBLE_DIR}/hacking/env-setup
PYTHONPATH="${ANSIBLE_DIR}/lib/:/usr/local/Cellar/ansible/" ansible-playbook test.yml

env-setup adds the first PATH but the second is specific to the Brew install so you need to add it manually.

If you run the above incorrectly, you will be missing modules and see errors like this:

Unexpected Exception: No module named yaml
the full traceback was:

Traceback (most recent call last):
    File "/Users/thanh/Downloads/ansible/ansible-", line 72, in <module>
        mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
    File "/Users/thanh/Downloads/ansible/", line 27, in <module>
        import yaml
ImportError: No module named yaml


Traceback (most recent call last):
    File "/Users/thanh/Downloads/ansible/ansible-", line 39, in <module>
    from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
ImportError: No module named ansible.errors