ansible: ImportError: No module named ansible.playbook

This article was published 6 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

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.

Thoughts on this post

Leave a comment?