Ansible installation from source (git clone) gives "ImportError: No module named ansible.runner"

Hi all,

I am trying to install ansible using “git clone” and it fails (have done that before a few times and it worked):

`

git clone https://github.com/ansible/ansible.git --recursive

Initialized empty Git repository in /opt/apps/ansible/.git/

remote: Counting objects: 102057, done.

remote: Total 102057 (delta 0), reused 0 (delta 0), pack-reused 102057

Receiving objects: 100% (102057/102057), 36.29 MiB | 7.88 MiB/s, done.

Resolving deltas: 100% (60887/60887), done.

Submodule ‘lib/ansible/modules/core’ (https://github.com/ansible/ansible-modules-core) registered for path ‘lib/ansible/modules/core’

Submodule ‘lib/ansible/modules/extras’ (https://github.com/ansible/ansible-modules-extras) registered for path ‘lib/ansible/modules/extras’

Initialized empty Git repository in /opt/apps/ansible/lib/ansible/modules/core/.git/

remote: Counting objects: 30223, done.

remote: Compressing objects: 100% (39/39), done.

remote: Total 30223 (delta 15), reused 0 (delta 0), pack-reused 30184

Receiving objects: 100% (30223/30223), 8.20 MiB | 3.45 MiB/s, done.

Resolving deltas: 100% (20054/20054), done.

Submodule path ‘lib/ansible/modules/core’: checked out ‘cd9a7667aa39bbc1ccd606ebebaf3c62f228d601’

Initialized empty Git repository in /opt/apps/ansible/lib/ansible/modules/extras/.git/

remote: Counting objects: 28690, done.

remote: Total 28690 (delta 0), reused 0 (delta 0), pack-reused 28690

Receiving objects: 100% (28690/28690), 7.78 MiB | 3.45 MiB/s, done.

Resolving deltas: 100% (18960/18960), done.

Submodule path ‘lib/ansible/modules/extras’: checked out ‘3c4f954f0fece5dcb3241d6d5391273334206241’

ls -la

total 32

drwxr-xr-x 5 root root 4096 Dec 4 10:54 .

drwxr-xr-x. 7 root root 4096 Dec 2 15:28 …

drwxr-xr-x 14 root root 4096 Dec 4 10:54 ansible

drwxr-xr-x 13 root root 4096 Dec 2 15:50 ansible.old

drwx------ 2 root root 16384 Jun 30 2014 lost+found

cd ansible

git tag -l

0.0.1

0.0.2

0.01

0.3

0.3.1

0.4

0.4.1

0.5

0.6

0.7

0.7.1

0.7.2

0.8

v0.9

v1.0

v1.1

v1.2

v1.2.1

v1.2.2

v1.2.3

v1.3.0

v1.3.1

v1.3.2

v1.3.3

v1.3.4

v1.4.0

v1.4.1

v1.4.2

v1.4.3

v1.4.4

v1.4.5

v1.5.0

v1.5.1

v1.5.2

v1.5.3

v1.5.4

v1.5.5

v1.6.0

v1.6.1

v1.6.10

v1.6.2

v1.6.3

v1.6.4

v1.6.5

v1.6.6

v1.6.7

v1.6.8

v1.6.9

v1.7.0

v1.7.1

v1.7.2

v1.8.0

v1.8.1

v1.8.2

v1.8.3

v1.8.4

v1.9.0-0.1.rc1

v1.9.0-0.2.rc2

v1.9.0-1

v1.9.0-2

v1.9.0.1-1

v1.9.1-0.1.rc1

v1.9.1-0.2.rc2

v1.9.1-0.3.rc3

v1.9.1-0.4.rc4

v1.9.1-1

v1.9.2-0.1.rc1

v1.9.2-0.2.rc2

v1.9.2-1

v1.9.3-0.1.rc1

v1.9.3-0.2.rc2

v1.9.3-0.3.rc3

v1.9.3-1

v1.9.4-0.1.rc1

v1.9.4-0.2.rc2

v1.9.4-0.3.rc3

v1.9.4-1

v2.0.0-0.1.alpha1

v2.0.0-0.2.alpha2

v2.0.0-0.3.beta1

v2.0.0-0.4.beta2

v2.0.0-0.5.beta3

v2.0.0-0.6.rc1

git checkout v1.9.4-1

M lib/ansible/modules/core

M lib/ansible/modules/extras

Note: checking out ‘v1.9.4-1’.

You are in ‘detached HEAD’ state. You can look around, make experimental

changes and commit them, and you can discard any commits you make in this

state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may

do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at 5af1cda… Version bump for release 1.9.4-1

source ./hacking/env-setup

running egg_info

creating lib/ansible.egg-info

writing requirements to lib/ansible.egg-info/requires.txt

writing lib/ansible.egg-info/PKG-INFO

writing top-level names to lib/ansible.egg-info/top_level.txt

writing dependency_links to lib/ansible.egg-info/dependency_links.txt

writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’

reading manifest file ‘lib/ansible.egg-info/SOURCES.txt’

reading manifest template ‘MANIFEST.in’

no previously-included directories found matching ‘v2’

no previously-included directories found matching ‘docsite’

no previously-included directories found matching ‘ticket_stubs’

no previously-included directories found matching ‘packaging’

no previously-included directories found matching ‘test’

no previously-included directories found matching ‘hacking’

writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’

Setting up Ansible to run out of checkout…

PATH=/opt/apps/ansible/bin:/usr/lib64/qt-3.3/bin:/opt/apps/ansible/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/IBM/nmon:/root/bin

PYTHONPATH=/opt/apps/ansible/lib:

MANPATH=/opt/apps/ansible/docs/man:

Remember, you may wish to specify your host file with -i

Done!

git pull --rebase

You are not currently on a branch, so I cannot use any

‘branch..merge’ in your configuration file.

Please specify which remote branch you want to use on the command

line and try again (e.g. ‘git pull ’).

See git-pull(1) for details.

git submodule update --init --recursive

Submodule path ‘lib/ansible/modules/core’: checked out ‘206a1247d911c8e9161c121d1d81d232985aa43a’

Submodule path ‘lib/ansible/modules/extras’: checked out ‘882ec41e12b6664dbed7ab5cb5352b1b5abd3857’

ansible --version

Traceback (most recent call last):

File “/opt/apps/ansible/bin/ansible”, line 36, in

from ansible.runner import Runner

ImportError: No module named ansible.runner

`

Can anyone tell what is wrong ? Can I fix it ?

Did you run

source hacking/env-setup

so that the paths can be set?

I think I’ve had similar when I’ve got a package install of ansible and pulled the source code on the same machine.

Hope this helps,

Jon

Yes, I did run “source ./hacking/env-setup”.
And this ansible is the installation on this server. There is no other (nor pip, tar.gz, etc).

I have had similar error before but it turned out I had install ansible using pip.
Now it is not that case.

I’ve forgotten to say that this is on Red Hat 6.5.

try running ‘make clean’ as ‘runner’ does not exist in 2.0, it seems you are getting 1.9 files in the mix, might be old .pyc that wont be removed by switching branches.

`

make clean

Cleaning up distutils stuff
rm -rf build
rm -rf dist
Cleaning up byte compiled python stuff
find . -type f -regex “..py[co]$" -delete
Cleaning up editor backup files
find . -type f ( -name "
~” -or -name “#" ) -delete
find . -type f ( -name "
.swp” ) -delete
Cleaning up manpage stuff
find ./docs/man -type f -name “.xml" -delete
find ./docs/man -type f -name "
.asciidoc” -delete
find ./docs/man/man3 -type f -name ".3" -delete
Cleaning up output from test runs
rm -rf test/test_data
Cleaning up RPM building stuff
rm -rf MANIFEST rpm-build
Cleaning up Debian building stuff
rm -rf debian
rm -rf deb-build
rm -rf docs/json
rm -rf docs/js
Cleaning up authors file
rm -f AUTHORS.TXT
find . -type f -name '
.pyc’ -delete

ansible --version

Traceback (most recent call last):
File “/opt/apps/ansible/bin/ansible”, line 36, in
from ansible.runner import Runner
ImportError: No module named ansible.runner

`

I also downloaded ansible-1.9.4-1.tar.gz and still have the same problem:

`

ansible --version

Traceback (most recent call last):
File “/opt/apps/ansible/bin/ansible”, line 36, in
from ansible.runner import Runner
ImportError: No module named ansible.runner

`

Are you using the release tarball or the github ones?

This one:
https://github.com/ansible/ansible/archive/v1.9.4-1.tar.gz

Those don’t work, they are autogenerated, go to releases.ansible.com

And I have just tried this one with no change (still problem):
https://releases.ansible.com/ansible/

Just for the record:

`

echo $PYTHONPATH

/opt/apps/ansible/lib:

echo $PATH

/opt/apps/ansible/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/IBM/nmon:/root/bin

`

I did this way as well. And no change - still the same error …

Well, of course if you forget about “make install” (me) it won’t work …
If you remember about it - it works.
But using “make install” installs files into /usr/lib/python2.6/site-packages/
Is there any way I can keep all ansible related files in i.e. /opt/apps/ansible and not mess with native packages ?

i just tested this with release tarball, the issue of running w/o an
install is that you don't have a hacking/env-setup in it.

so i did this after downloading from releases.ansible.com/ansible/:

tar xcvfz ~/Downloads/ansible-1.9.4.tar.gz -C ~/tmp/
cd ~/tmp/ansible-1.9.4
mkdir hacking
cd hacking
wget https://raw.githubusercontent.com/ansible/ansible/devel/hacking/env-setup
cd ..
. hacking/env-setup

ansible --version
ansible 1.9.4
  configured module search path = None

Also tried with a play and it works fine.

i just find git clone method easier.

Hi Brian,

I also find git clone method easier except … it doesn’t work …
I mean which step is missing from my list of steps (I am just following the steps from official Ansible web page) ?

Ok. Once again repeating steps from the official webpage:

`

git clone https://github.com/ansible/ansible.git --recursive

Initialized empty Git repository in /opt/apps/ansible/.git/
remote: Counting objects: 102829, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 102829 (delta 1), reused 0 (delta 0), pack-reused 102824
Receiving objects: 100% (102829/102829), 36.27 MiB | 7.31 MiB/s, done.
Resolving deltas: 100% (61433/61433), done.
Submodule ‘lib/ansible/modules/core’ (https://github.com/ansible/ansible-modules-core) registered for path ‘lib/ansible/modules/core’
Submodule ‘lib/ansible/modules/extras’ (https://github.com/ansible/ansible-modules-extras) registered for path ‘lib/ansible/modules/extras’
Initialized empty Git repository in /opt/apps/ansible/lib/ansible/modules/core/.git/
remote: Counting objects: 30323, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 30323 (delta 2), reused 0 (delta 0), pack-reused 30311
Receiving objects: 100% (30323/30323), 8.18 MiB | 4.51 MiB/s, done.
Resolving deltas: 100% (20131/20131), done.
Submodule path ‘lib/ansible/modules/core’: checked out ‘0d23b3df526875c8fc6edf94268f3aa850ec05f1’
Initialized empty Git repository in /opt/apps/ansible/lib/ansible/modules/extras/.git/
remote: Counting objects: 28803, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 28803 (delta 10), reused 0 (delta 0), pack-reused 28782
Receiving objects: 100% (28803/28803), 7.79 MiB | 4.06 MiB/s, done.
Resolving deltas: 100% (19075/19075), done.
Submodule path ‘lib/ansible/modules/extras’: checked out ‘51813e003331c3341b07c5cda33346cada537a3b’

cd ansible

source ./hacking/env-setup

running egg_info
creating lib/ansible.egg-info
writing requirements to lib/ansible.egg-info/requires.txt
writing lib/ansible.egg-info/PKG-INFO
writing top-level names to lib/ansible.egg-info/top_level.txt
writing dependency_links to lib/ansible.egg-info/dependency_links.txt
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’
reading manifest file ‘lib/ansible.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
no previously-included directories found matching ‘v2’
no previously-included directories found matching ‘docsite’
no previously-included directories found matching ‘ticket_stubs’
no previously-included directories found matching ‘packaging’
no previously-included directories found matching ‘test’
no previously-included directories found matching ‘hacking’
writing manifest file ‘lib/ansible.egg-info/SOURCES.txt’

Setting up Ansible to run out of checkout…

PATH=/opt/apps/ansible/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/IBM/nmon:/root/bin
PYTHONPATH=/opt/apps/ansible/lib/:
MANPATH=/opt/apps/ansible/docs/man:

Remember, you may wish to specify your host file with -i

Done!

ansible --version

Traceback (most recent call last):
File “/opt/apps/ansible/bin/ansible”, line 39, in
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
ImportError: No module named ansible.errors

echo $PATH

/opt/apps/ansible/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/IBM/nmon:/root/bin

echo $PYTHONPATH

/opt/apps/ansible/lib/:

`

So what is wrong with it ?

There is something really weird going on, the exact same steps work
fine for me, your pythonpath is correct and should be able to find the
files.

Can you confirm that /opt/apps/ansible/lib/ansible/errors/__init__.py exists?

“Freshly” cloned again today:

`

ls -la /opt/apps/ansible/lib/ansible/errors/init.py

-rw-r–r-- 1 root root 7738 Dec 11 11:42 /opt/apps/ansible/lib/ansible/errors/init.py

`

I also don’t understand what is going on.
When I clone it it has many releases in it. Don’t I need to checkout one of them at the very begin ?

Can I turn on some debugging/verbose options ?

Clone will automatically give you 'devel' which is the 'most current'.
There are verbose options, but they won't workas you are failing on
the basic import before anything gets run.

what does this return?

/usr/bin/env python --version