Ansible installation using pip broken?

Hi there,

I am trying to install Ansible within a Docker container (plain Ubuntu 14.04) to be used as a test environment.
The Python version is managed by pyenv, and I am using pip to install Ansible. This is the output of the “pip freeze” command after installing Ansible:


root@7e408538fd38:/usr/src/myapp# pip freeze
ansible==2.0.0.2
chardet==2.3.0
colorama==0.2.5
ecdsa==0.13
html5lib==0.999
httplib2==0.8
Jinja2==2.8
MarkupSafe==0.23
paramiko==1.16.0
pycrypto==2.6.1
python-distutils-extra==2.28
PyYAML==3.11
requests==2.2.1
six==1.5.2
urllib3==1.7.1
wheel==0.24.0

When I run one of my playbooks that uses the apt module, I get the following error indicating that the python-apt module is missing:

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Could not import python modules: apt, apt_pkg. Please install python-apt package."}

When trying to install python-apt module manually using pip, I get an error about more modules missing:


root@c833f66ef7c0:/usr/src/myapp# pip install python-apt
Collecting python-apt
Downloading python-apt-0.7.8.tar.bz2 (49kB)
100% |################################| 53kB 84kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-y4ASYs/python-apt/setup.py", line 6, in <module>
from DistUtilsExtra.command import *
ImportError: No module named DistUtilsExtra.command

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-y4ASYs/python-apt

I would expect these dependencies to me managed by pip when installing the Ansible package. Am I missing anything?

Any input would be appreciated.
Thanks for your help.

Angel

python-apt is a dependency not of ansible master, but of the apt module, it must be installed on the ‘target’ machine not on the ‘master’.

The module itself should try to install it automatically, but it seems there are issues with that in your systems.

Thanks Brian.

You are right. The module installs the python-apt package on the target instance, but the module will only be available to the Ubuntu Python installation (/usr/lib/python2.7/dist-packages/apt/), not the one managed by pyenv.

I tried to install the python-apt module using pip (within the pyenv-managed Python installation), but get a dependency error:

root@617d09e567c1:/usr/src/myapp# pip install python-apt
Collecting python-apt
Downloading python-apt-0.7.8.tar.bz2 (49kB)
100% |################################| 53kB 168kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-build-W6kZPY/python-apt/setup.py”, line 6, in
from DistUtilsExtra.command import *
ImportError: No module named DistUtilsExtra.command

I’ve run into this problem as well - It’s annoying :confused:

When I run with system python, I can use apt/yum/etc, but when I use virtualenvs, there’s always complications with dist-only packages.
I haven’t found any easy way to work around these.
My solution has been to replace the apt/yum lines with shell calls instead, but I’d love a better way to do this.