ansible: ImportError: No module named ansible.playbook

TL;DR: brew link --overwrite ansible

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

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

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

$ 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:

$ 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:

$ 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.

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

Let’s check if it works

$ ansible --version
ansible 1.4.4

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

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply