ansible: ImportError: No module named ansible.playbook

08 Mar 2014 in TIL

TL;DR: brew link --overwrite ansible

This week I tried to run ansible-playbook on OSX and received the following error message:

bash
$ ansible-playbook
ImportError: No module named ansible.playbook

I also tried running ansible, but that didn't work either

bash
$ ansible
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 24, in <module>
from ansible.runner import Runner
ImportError: No module named ansible.runner

Strange! The binaries exist but the actual underlying code wasn't there. I decided to try reinstalling:

bash
$ brew install ansible
Warning: ansible-1.4.4 already installed, it's just not linked

Aha! So we have it installed but it's not available. Let's try and link everything needed:

bash
$ brew link ansible
Linking /usr/local/Cellar/ansible/1.4.4... Warning: Could not link ansible. Unlinking...
Error: Could not symlink file: /usr/local/Cellar/ansible/1.4.4/bin/ansible-pull
Target /usr/local/bin/ansible-pull already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
brew link --overwrite formula_name

It didn't work as it already exists. It was already broken, so running with --overwrite wouldn't break anything for me.

bash
$ brew link --overwrite ansible
Linking /usr/local/Cellar/ansible/1.4.4... 92 symlinks created

Let's check if it works

bash
$ ansible --version
ansible 1.4.4

Job done! ansible and ansible-playbook work fine again.