Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to import docker-py for docker_container module #20492

Closed
guenhter opened this issue Jan 20, 2017 · 64 comments
Closed

Failed to import docker-py for docker_container module #20492

guenhter opened this issue Jan 20, 2017 · 64 comments
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. cloud docker module This issue/PR relates to a module.

Comments

@guenhter
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_container

ANSIBLE VERSION
ansible 2.3.0 (devel 216e2c8813) last updated 2017/01/20 09:22:29 (GMT +000)
ansible 2.2.0.0 (detached HEAD cdec853e37) last updated 2017/01/20 09:25:31 (GMT +000)
CONFIGURATION

Nothing changed

OS / ENVIRONMENT

Linux machine1 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux

pip list:

pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
backports.ssl-match-hostname (3.5.0.1)
cached-property (1.3.0)
chardet (2.3.0)
colorama (0.3.7)
defusedxml (0.4.1)
docker (2.0.2)
docker-compose (1.10.0)
docker-py (1.10.6)
docker-pycreds (0.2.1)
dockerpty (0.4.1)
docopt (0.6.2)
docutils (0.12)
enum34 (1.1.6)
functools32 (3.2.3.post2)
iotop (0.6)
ipaddress (1.0.18)
jsonschema (2.5.1)
Pillow (2.6.1)
pip (9.0.1)
Pygments (2.0.1)
python-apt (0.9.3.12)
python-debian (0.1.27)
python-debianbts (1.11)
PyYAML (3.12)
reportbug (6.6.3)
requests (2.11.1)
roman (2.0.0)
setuptools (5.5.1)
six (1.10.0)
SOAPpy (0.12.22)
texttable (0.8.7)
websocket-client (0.40.0)
wstools (0.4.3)

python --version
Python 2.7.9

docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 0
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge null overlay host
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options:
Kernel Version: 3.16.0-4-amd64
Operating System: Debian GNU/Linux 8 (jessie)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.963 GiB
Name: machine1
ID: PD6F:VQDI:VAK4:O3YU:PWDT:HFAG:T3Z4:FNP5:QLT7:C3TO:7OKS:OODH
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory limit support
WARNING: No oom kill disable support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
Insecure Registries:
 127.0.0.0/8
SUMMARY

When module docker_container is used, it fails every time with

"Failed to import docker-py - cannot import name Client. Try `pip install docker-py`"
STEPS TO REPRODUCE
  - docker_container:
      image: hello-world
      name: hello
EXPECTED RESULTS

Image is executed.

ACTUAL RESULTS
TASK [docker-registry : docker_container] **************************************
task path: /vagrant/service-playbooks/roles/docker-registry/tasks/registry-server.yml:56
Using module file /home/vagrant/ansible/lib/ansible/modules/core/cloud/docker/docker_container.py
<192.168.77.201> ESTABLISH SSH CONNECTION FOR USER: deploy
<192.168.77.201> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deploy -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.77.201 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817 `" && echo ansible-tmp-1484904632.51-163570270155817="` echo $HOME/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817 `" ) && sleep 0'"'"''
<192.168.77.201> PUT /tmp/tmpeXfDvf TO /home/deploy/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817/docker_container.py
<192.168.77.201> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deploy -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.77.201]'
<192.168.77.201> ESTABLISH SSH CONNECTION FOR USER: deploy
<192.168.77.201> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deploy -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.77.201 '/bin/sh -c '"'"'chmod u+x /home/deploy/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817/ /home/deploy/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817/docker_container.py && sleep 0'"'"''
<192.168.77.201> ESTABLISH SSH CONNECTION FOR USER: deploy
<192.168.77.201> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=deploy -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.77.201 '/bin/sh -c '"'"'/usr/bin/python /home/deploy/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817/docker_container.py; rm -rf "/home/deploy/.ansible/tmp/ansible-tmp-1484904632.51-163570270155817/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [machine_1]: FAILED! => {
    "changed": false,
    "failed": true,
    "invocation": {
        "module_args": {
            "api_version": null,
            "blkio_weight": null,
            "cacert_path": null,
            "capabilities": null,
            "cert_path": null,
            "cleanup": false,
            "command": null,
            "cpu_period": null,
            "cpu_quota": null,
            "cpu_shares": null,
            "cpuset_cpus": null,
            "cpuset_mems": null,
            "debug": false,
            "detach": true,
            "devices": null,
            "dns_opts": null,
            "dns_search_domains": null,
            "dns_servers": null,
            "docker_host": null,
            "entrypoint": null,
            "env": null,
            "env_file": null,
            "etc_hosts": null,
            "exposed_ports": null,
            "filter_logger": false,
            "force_kill": false,
            "groups": null,
            "hostname": null,
            "ignore_image": false,
            "image": "hello-world",
            "interactive": false,
            "ipc_mode": null,
            "keep_volumes": true,
            "kernel_memory": null,
            "key_path": null,
            "kill_signal": null,
            "labels": null,
            "links": null,
            "log_driver": null,
            "log_options": null,
            "mac_address": null,
            "memory": "0",
            "memory_reservation": null,
            "memory_swap": null,
            "memory_swappiness": null,
            "name": "hello",
            "network_mode": null,
            "networks": null,
            "oom_killer": null,
            "oom_score_adj": null,
            "paused": false,
            "pid_mode": null,
            "privileged": false,
            "published_ports": null,
            "pull": false,
            "purge_networks": false,
            "read_only": false,
            "recreate": false,
            "restart": false,
            "restart_policy": null,
            "restart_retries": null,
            "security_opts": null,
            "shm_size": null,
            "ssl_version": null,
            "state": "started",
            "stop_signal": null,
            "stop_timeout": null,
            "timeout": null,
            "tls": null,
            "tls_hostname": null,
            "tls_verify": null,
            "trust_image_content": false,
            "tty": false,
            "ulimits": null,
            "user": null,
            "uts": null,
            "volume_driver": null,
            "volumes": null,
            "volumes_from": null
        },
        "module_name": "docker_container"
    },
    "msg": "Failed to import docker-py - cannot import name Client. Try `pip install docker-py`"
}
	to retry, use: --limit @/vagrant/service-playbooks/microservice-infrastructure-no-elastic.retry
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report cloud docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Jan 20, 2017
@jctanner
Copy link
Contributor

jctanner commented Jan 20, 2017

@guenhter It appears that the task is ssh'ing to 192.168.77.201 as the "deploy" user. Was the "pip list" output in the description gathered as that user on that host?

ssh deploy@192.168.77.201 'python -c "import docker-py"'

needs_info

@jctanner jctanner removed the needs_triage Needs a first human triage before being processed. label Jan 20, 2017
@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Jan 20, 2017
@jpiron
Copy link
Contributor

jpiron commented Jan 20, 2017

@guenhter
This is due to your docker-compose version.
The docker-py package has been renamed into docker in version 2.0 (https://github.com/docker/docker-py/releases/tag/2.0.0). And in this version, Docker.Client has been renamed into docker.APIClient.
Docker-compose 1.10+ now requires docker instead of docker-py. And due to his name the docker package is before the docker-py one in the PYTHONPATH leading to the import error.
A workaround is to downgrade your docker-compose version to 1.9.0 the time the Ansible docker_container module updates its dependencies from docker-py to docker.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Jan 20, 2017
@guenhter
Copy link
Author

guenhter commented Jan 23, 2017

@jctanner
The pip list output was from that host. See some more commands below:

ssh deploy@192.168.77.201 'python --version'
--> Python 2.7.9

ssh deploy@192.168.77.201 'python -c "import docker-py"'

--> File "<string>", line 1
    import docker-py
                 ^
SyntaxError: invalid syntax



ssh deploy@192.168.77.201 'pip list'
-->DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
backports.ssl-match-hostname (3.5.0.1)
cached-property (1.3.0)
chardet (2.3.0)
colorama (0.3.7)
defusedxml (0.4.1)
docker (2.0.2)
docker-compose (1.10.0)
docker-py (1.10.6)
docker-pycreds (0.2.1)
dockerpty (0.4.1)
docopt (0.6.2)
docutils (0.12)
enum34 (1.1.6)
functools32 (3.2.3.post2)
iotop (0.6)
ipaddress (1.0.18)
jsonschema (2.5.1)
Pillow (2.6.1)
pip (9.0.1)
Pygments (2.0.1)
python-apt (0.9.3.12)
python-debian (0.1.27)
python-debianbts (1.11)
PyYAML (3.12)
reportbug (6.6.3)
requests (2.11.1)
roman (2.0.0)
setuptools (5.5.1)
six (1.10.0)
SOAPpy (0.12.22)
texttable (0.8.7)
websocket-client (0.40.0)
wstools (0.4.3)

@guenhter
Copy link
Author

@jpiron
I tried to downgrade docker-compse --> same error
Also uninstallation of it didn't help.

@jpiron
Copy link
Contributor

jpiron commented Jan 23, 2017

docker-py is just the name of the project. It installs a python package named docker. So you should run:

# python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> print(docker.version)
1.10.6
>>>

Downgrading docker-compose won't remove the docker package from the docker project which is installed on your server according to your pip output.
The following should fix your issue:

pip uninstall docker
pip uninstall docker-py
pip uninstall docker-compose
pip install docker-compose==1.9.0

@guenhter
Copy link
Author

@jpiron
This works perfectly fine. Thanks!

But IMO this is just a workaround to get things keep running.
Nevertheless should this be fixed to avoid downgrading docker-compose.

@ekarlso
Copy link

ekarlso commented Jan 29, 2017

Any news on this?

@mtbvang
Copy link

mtbvang commented Jan 29, 2017

I'm getting the same error trying to use docker_image. Should I open a new issue or is this exactly the same issue?


- name: Test docker install by pulling hello world image
      docker_image:
        name: hello-world

fatal: [devhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - cannot import name Client. Try `pip install docker-py`"}
	
pip list | grep docker

docker (2.0.2)
docker-compose (1.9.0)
docker-py (1.10.6)
docker-pycreds (0.2.1)
dockerpty (0.4.1)

@jpiron
Copy link
Contributor

jpiron commented Jan 30, 2017

It won't work with both docker and docker-py installed. you should remove docker and reinstall docker-py:

pip uninstall docker
pip install --ignore-installed docker-py

This should solve your issue.

@jpiron
Copy link
Contributor

jpiron commented Jan 30, 2017

This commit e2a1ce2 should solve the issue. Until it gets released I guess we have stick with docker-compose<=1.9.0.

@antoinetran
Copy link

antoinetran commented Feb 8, 2017

We had to remove docker-compose 1.10 (pip-version), and all its dependencies (mostly module docker). We did a diff from a clean state and a "polluted" state (with docker-compose 1.10 in pip installed): to revert, we did:
for pipPackage in cached-property colorama docker docker-compose dockerpty docopt functools32 jsonschema texttable docker-py ; do sudo pip uninstall -y ${pipPackage} 2>&1 | logger -i -t TestRemove ; done
Then we installed docker-compose 1.10 with curl method (see official doc). No issue with docker_container resource. There is an issue with docker_service, because it needs docker-compose in python instead. But we don't use docker_service anymore. Pip dependencies are a hell that we want to avoid from now on!! This is the best solution we have for now.

@harobed
Copy link

harobed commented Feb 25, 2017

This commit e2a1ce2 should solve the issue.

This patch isn't present in Ansible 2.2.1.0.

@guenhter
Copy link
Author

guenhter commented Mar 7, 2017

I tried this today with tags/v2.2.2.0-0.2.rc2
but still have the problem:

deploy@machine1:/home/vagrant$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
backports.ssl-match-hostname (3.5.0.1)
cached-property (1.3.0)
chardet (2.3.0)
colorama (0.3.7)
defusedxml (0.4.1)
docker (2.1.0)
docker-compose (1.11.2)
docker-py (1.10.6)
docker-pycreds (0.2.1)
dockerpty (0.4.1)
docopt (0.6.2)
docutils (0.12)
enum34 (1.1.6)
functools32 (3.2.3.post2)
iotop (0.6)
ipaddress (1.0.18)
jsonschema (2.6.0)
Pillow (2.6.1)
pip (9.0.1)
Pygments (2.0.1)
python-apt (0.9.3.12)
python-debian (0.1.27)
python-debianbts (1.11)
PyYAML (3.12)
reportbug (6.6.3)
requests (2.13.0)
roman (2.0.0)
setuptools (5.5.1)
six (1.10.0)
SOAPpy (0.12.22)
texttable (0.8.7)
websocket-client (0.40.0)
wstools (0.4.3)

deploy@machine1:/home/vagrant$ docker-compose
ERROR: Dependency conflict: an older version of the 'docker-py' package is polluting the namespace. Run the following command to remedy the issue:
pip uninstall docker docker-py; pip install docker

On the other hand, when docker-py is not installed (pip uninstall docker-py) than ansible complains:

Failed to import docker-py - No module named docker. Try `pip install docker-py`

@viossat
Copy link

viossat commented Mar 7, 2017

@guenhter,
Install Ansible 2.3.0 (devel): pip install git+git://github.com/ansible/ansible.git@devel
It now includes e2a1ce2 which fixes the compatibility issue.

@guenhter
Copy link
Author

guenhter commented Mar 7, 2017

When will this be available in a release?

@kivio
Copy link

kivio commented Mar 14, 2017

Any news on this?

@jpiron
Copy link
Contributor

jpiron commented Mar 18, 2017

As @viossat said, e2a1ce2 is included in the 2.3.0 version.
It solves the issue even with both docker and the old docker-py packages installed. You can try it out:

virtualenv -p /usr/bin/python2.7 /tmp/venv
source /tmp/venv/bin/activate
pip install https://github.com/ansible/ansible/archive/v2.3.0.0-0.1.rc1.zip
pip install docker docker-py
ansible localhost -m docker_container -a "name=foo image=busybox"

@eihli
Copy link

eihli commented Oct 20, 2017

Edit - working - user error: In my case, this was not a bug. To anyone else experiencing this, try running ansible with -vvvv. I saw that ansible was using /usr/bin/python. I had to set ansible_python_interpreter to the python executable on my host machine in the virtualenv where pip was installing things. That changed the error to file not found which made me realize all of the error was coming from the target machine. So I switched ansible_python_interpreter to be the python executable of the target machine, installed docker-py on the target machine, and got a different error about some other related dependency (websockets or requests or something) not being installed. Then I uninstalled docker/docker-py on the target machine and installed docker-compose. Then everything worked.


Original text - pre-edit:

Just an update with some more info on a failing system.

Mac 10.12.6
Docker Version 17.09.0-ce-mac35 (19611)
ansible 2.4.0.0
pip uninstall docker docker-py docker-compose
pip install docker-compose

docker_image

FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"}
ansible localhost -m shell -a "python -c 'import requests.exceptions'"
localhost | SUCCESS | rc=0 >>

@bakarov
Copy link

bakarov commented Dec 21, 2017

I had the sample problem,
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "msg": "Failed to import docker-py - No module named requests.exceptions. Try 'pip install docker-py'"}

Nothing mentioned in this thread helped. I downgraded ansible, and everything worked.
pip install ansible==2.3.3.0

@jwkohnen
Copy link
Contributor

Users keep running into this issue since one year. Why is this ticket closed?

@matti
Copy link

matti commented Jan 10, 2018

Timo Soini

@IoTPlay
Copy link

IoTPlay commented Jan 18, 2018

Same problem, "Controller" on Mac, "Managed-Host" on RPi, have been struggling with this for 3 weeks. I logged my own issue, they closed it, so where do we go from here?

Here is what I opened, and got promptly closed. #34851

"This is not a problem with ansible, but instead a potential problem with upstream docker-py/docker: docker/docker-py#1353

But no answer at above link either.

@teamextension
Copy link

I was getting the error and running "pip install docker-py" fixed it, just as the error message said. Ansible 2.4.2.0.

magical added a commit to osu-mist/ansible-roles that referenced this issue Mar 6, 2018
Prior to ansible 2.4, ansible required an old version of docker-py
which conflicts with docker-compose. (This is because docker-py 2.0 and
later renamed a class that ansible depended on).

The error was something like this:

    fatal: [ci]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - cannot import name Client. Try `pip install docker-py`"}

See e.g.,

    ansible/ansible#20380
    ansible/ansible#20492
    https://stackoverflow.com/questions/38181433/ansible-cannot-import-docker-py-even-though-it-is-installed

Ansible 2.3 was updated to (mostly) be compatible with newer versions of the
docker-py library, and ansible 2.4 improved support further.

    ansible/ansible@e2a1ce2
    ansible/ansible@51a9875

Bump the version we say that we require so that nobody else has to
run into this error.
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@antoinetran
Copy link

Why is this issue closed? We installed latest ansible 2.4.2.0 in latest RedHat 7.4, that is a clean machine from scratch. It requires docker-py and python3 is not installed. Ansible RPM provides docker.py, and NOT docker-py. It is inconsistent of Ansible to install docker.py and to use docker-py.py.

@akhilputhiry
Copy link

I am facing the issue in ansible==2.5.0. Any help is highly appreciated.

@ryansb
Copy link
Contributor

ryansb commented Mar 29, 2018

Please try the resolution mentioned here #20492 (comment) - Ansible includes a docker module, but DOES NOT include the docker SDK (needed to communicate with docker daemon). That needs to be installed if you want to use the module.

@dmsimard
Copy link
Contributor

dmsimard commented Apr 2, 2018

@ryansb I am able to reproduce the issue with Ansible 2.5.0 on python3.

fatal: [db01]: FAILED! => {"changed": false, "msg": "Failed to import docker-py - No module named requests.exceptions. Try `pip install docker-py`"}

Despite:

$ pip3 freeze |grep docker
docker-py==1.10.6
docker-pycreds==0.2.2

Downgrading to Ansible 2.4.3.0 doesn't resolve the issue.
I have a suspicion that this might have to do with py2 vs py3 but I don't have the time to reproduce on py2 right now.

FWIW I'm seeing this both on Ubuntu and Fedora as the control node.

@disassembler
Copy link

disassembler commented Apr 4, 2018 via email

@akhilputhiry
Copy link

@ryansb Thank you for the help. But unfortunately it didn't fix the issue.

@ravindranathakila
Copy link

nix

> nix-env -qa|grep sible
python2.7-ansible-2.1.4.0
python2.7-ansible-2.2.1.0
python2.7-ansible-2.3.2.0
python2.7-ansible-2.4.2.0
python2.7-ansible-lint-3.4.20
vimplugin-sensible-2018-01-22
> nix-env -i python2.7-ansible-2.4.2.0

@ravindranathakila
Copy link

Please re-open this issue.

@antoinetran
Copy link

@jpiron do you have an updated status related to this?

@lifenautjoe
Copy link

Went through the whole thread solutions, none worked.

fatal: [172.16.101.44]: FAILED! => {"changed": false, "msg": "Failed to import docker-py - No module named 'docker'. Try `pip install docker-py`"}

@antoinetran
Copy link

@lifenautjoe have you tried #20492 (comment)

@ryansb
Copy link
Contributor

ryansb commented Apr 17, 2018

If you've installed the docker-py module and still have this issue, it is because you are not using the correct Python interpreter with Ansible. If, for example, you have both Python 2 and 3 installed and install with pip3 install docker-py but Ansible is using Python 2, it will not see the module as it is installed in the Python3 site-packages directory.

In this case, you will need to set ansible_python_interpreter on the host in your inventory. See http://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html for more information about ansible_python_interpreter.

This is not an Ansible bug, this is a problem in the system Python environment.

@lifenautjoe
Copy link

Hi @antoinetran , I did. I actually started with python3 and downgraded to python2 now. Still errors but now related to requests package (installing it does not solve it either) ☹️

@ryansb
Copy link
Contributor

ryansb commented Apr 17, 2018

@lifenautjoe this seems to be an issue with your system. If you need help, please head to either Google Groups or the #ansible channel on Freenode to seek advice from the community. https://docs.ansible.com/ansible/latest/community/communication.html

@ghaithdallaali
Copy link

ghaithdallaali commented Apr 20, 2018

tldr; do the un/installations above on the target host.

I was hitting this error using the docker_service and docker_container ansible modules. I tried everything above but none worked. I spent an embarrassingly long time trying to figure out what was going on until I realized that the error is coming from my remote target... All I had to do was follow @jpiron comment to install docker-compose 1.9.0 on the remote target instead of my local venv where my playbooks exist and everything worked.

Hope this solves some mysteries.

@nickkadams
Copy link

nickkadams commented Apr 20, 2018

Like others, I was receiving the same error Failed to import docker-py via a Terraform build.

pip install --user --upgrade pip

was breaking things for me. Here is my working environment:

Ubuntu 16.04
- python 2.7.12
- pip 8.1.1
- ansible 2.5.1
- docker 18.03.0-ce
- docker-compose 1.21.0

Hope that helps.

@alex3305
Copy link

Still facing issues regarding this package in 2.5.3. When having docker-py installed within Python2.7, the docker-container module works great, but the docker-service doesn't because it requires Docker compose to be installed.

When following the installation instructions provided by Ansible pip install docker-compose, it also installs the Python 3 version of the docker package, which breaks the docker-container module. Manually removing docker doesn't help either and still fails with a Failed to import docker-py message.

It is very unclear how to continue and have both modules working at the same time.

@antoinetran
Copy link

At this point, it may be better to open a new issue, as this one is closed and maybe the Ansible developers do not look at this anymore.

@ansible ansible locked as resolved and limited conversation to collaborators May 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. cloud docker module This issue/PR relates to a module.
Projects
None yet
Development

No branches or pull requests