pythonpipansiblerhel6

ImportError: No module named ansible after installing Ansible 2.9 via PIP


Would like to know if anyone encountered this same concern I've been receiving:

Traceback (most recent call last):
  File "/usr/local/ansible2.9/bin/ansible-playbook", line 34, in <module>
    from ansible import context
ImportError: No module named ansible

So we have 2 ansible versions installed on our server and would like to run some jobs in ansible 2.9, we created separate environments per versions. So I activated ansible 2.9 env then proceeded to run the usual command "ansible-playbook playbook.yml .... " but we're getting this error.

The package was installed via pip, please see below:

[root@jenkins local]# virtualenv-2.7 --no-site-packages /usr/local/ansible2.9
New python executable in /usr/local/ansible2.9/bin/python2.7
Also creating executable in /usr/local/ansible2.9/bin/python
Installing setuptools, pip, wheel...done.
[root@jenkins local]# source /usr/local/ansible2.9/bin/activate
(ansible2.9) [root@jenkins local]# pip2.7 install git+git://github.com/ansible/ansible.git@stable-2.9

Please note that all required libraries have been installed. Python 2.7 is also installed. I'm using RHEL 6. Ansible 2.7 environment works fine, but this recently installed version is throwing "ImportError: No module named ansible"

Any idea how to fix this? Thanks!


Solution

  • Found the solution. It seems that the permission of the Ansible 2.9 has not been set properly. Fixed it with this commands:

    chmod -R 644 /usr/local/ansible2.9/ find /usr/local/ansible2.9/ -type d -print0 |xargs -0 chmod 755

    Also, for Ansible 2.9 together with openstack, openstacksdk will not suffice, still need to install 'future' library.

    Command: pip install ansible openstacksdk future Source: Issue - https://github.com/ansible/ansible/issues/68616 Fix - https://github.com/atodorov/lorax/commit/5103e0b585564c62e3007b68d945fc56a542c474