docker_container
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)
Nothing changed
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
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`"
- docker_container:
image: hello-world
name: hello
Image is executed.
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
@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 [email protected] 'python -c "import docker-py"'
needs_info
@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.
@jctanner
The pip list output was from that host. See some more commands below:
ssh [email protected] 'python --version'
--> Python 2.7.9
ssh [email protected] 'python -c "import docker-py"'
--> File "<string>", line 1
import docker-py
^
SyntaxError: invalid syntax
ssh [email protected] '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)
@jpiron
I tried to downgrade docker-compse
--> same error
Also uninstallation of it didn't help.
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
@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.
Any news on this?
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)
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.
This commit e2a1ce2916e9b87fe1ad4a1011c04ef8d2faf046 should solve the issue. Until it gets released I guess we have stick with docker-compose<=1.9.0.
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.
This commit e2a1ce2 should solve the issue.
This patch isn't present in Ansible 2.2.1.0
.
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`
@guenhter,
Install Ansible 2.3.0 (devel): pip install git+git://github.com/ansible/ansible.git@devel
It now includes e2a1ce2916e9b87fe1ad4a1011c04ef8d2faf046 which fixes the compatibility issue.
When will this be available in a release?
Any news on this?
As @viossat said, e2a1ce2916e9b87fe1ad4a1011c04ef8d2faf046 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"
Support for the new docker libraries is included in the Ansible 2.3 release. Since this is (IMO) a feature to add new support for docker-py v2, I don't think this fits in our backport policy.
Works great with ansible 2.3
I just had to ensure, that docker-py
is no longer installed but docker
is available (via pip).
Thanks a lot!
As @guenhter says. It works with Ansible 2.3 if you remove the old docker-py module
- name: remove docker-py
pip:
name: docker-py
state: absent
- name: Install docker python module
pip:
name: "docker-compose==1.12.0"
@martonsz Hello I have Ansible 2.3 but
- name: Test docker install by pulling hello world image
docker_container:
name: hello-world
don't work for me.
pip list:
backports.ssl-match-hostname (3.5.0.1)
cached-property (1.3.0)
cffi (1.5.2)
chardet (2.3.0)
click (6.7)
colorama (0.3.7)
configobj (5.0.6)
Django (1.9.4)
django-debug-toolbar (1.4)
docker (2.2.1)
docker-compose (1.12.0)
docker-pycreds (0.2.1)
dockerpty (0.4.1)
docopt (0.6.2)
html5lib (0.999)
jsonschema (2.6.0)
misaka (2.0.0)
mycli (1.8.1)
mysqlclient (1.3.7)
okapi2 (0.0.1)
pip (8.1.1)
prompt-toolkit (1.0.13)
pycparser (2.14)
pycrypto (2.6.1)
Pygments (2.2.0)
pygobject (3.14.0)
PyMySQL (0.7.10)
python-apt (0.9.3.12)
PyYAML (3.12)
requests (2.11.1)
setuptools (5.5.1)
six (1.8.0)
sqlparse (0.2.1)
texttable (0.8.8)
unattended-upgrades (0.1)
urllib3 (1.9.1)
uWSGI (2.0.12)
virtualenv (15.0.1)
wcwidth (0.1.7)
websocket-client (0.40.0)
Error:
TASK [confluence : Test docker install by pulling hello world image] *************************************
fatal: [web1-vultr]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"}
to retry, use: --limit @/home/martin/Work/ansible/site.retry
ansible --version:
ansible 2.3.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
@Applemann I had installed "docker-py" previously -- I had to pip uninstall docker; pip install docker
and then it started working... no idea what happened.
@matti I resolved it by add parameter -e 'ansible_python_interpreter=/usr/bin/python3'
when I run ansible-playbook.
Because on the server is using python3, but on my localhost was default python 2.7
I'm still having this problem with 2.3.0.0.
Have documented on Stack Overflow here: http://stackoverflow.com/a/43975079/1064619
Steps to reproduce:
I created a new VirtualEnv:
zoidberg:foley chris$ virtualenv ansible-test
New python executable in /Users/chris/src/hc/foley/ansible-test/bin/python2.7
Also creating executable in /Users/chris/src/hc/foley/ansible-test/bin/python
Installing setuptools, pip, wheel...done.
Installed Ansible:
(ansible-test) zoidberg:foley chris$ pip install ansible
Collecting ansible
Collecting pycrypto>=2.6 (from ansible)
Collecting paramiko (from ansible)
Using cached paramiko-2.1.2-py2.py3-none-any.whl
Collecting jinja2 (from ansible)
Using cached Jinja2-2.9.6-py2.py3-none-any.whl
Requirement already satisfied: setuptools in ./ansible-test/lib/python2.7/site-packages (from ansible)
Collecting PyYAML (from ansible)
Collecting cryptography>=1.1 (from paramiko->ansible)
Using cached cryptography-1.8.1-cp27-cp27m-macosx_10_10_intel.whl
Collecting pyasn1>=0.1.7 (from paramiko->ansible)
Using cached pyasn1-0.2.3-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from jinja2->ansible)
Requirement already satisfied: six>=1.6.0 in ./ansible-test/lib/python2.7/site-packages (from setuptools->ansible)
Requirement already satisfied: packaging>=16.8 in ./ansible-test/lib/python2.7/site-packages (from setuptools->ansible)
Requirement already satisfied: appdirs>=1.4.0 in ./ansible-test/lib/python2.7/site-packages (from setuptools->ansible)
Collecting idna>=2.1 (from cryptography>=1.1->paramiko->ansible)
Using cached idna-2.5-py2.py3-none-any.whl
Collecting enum34 (from cryptography>=1.1->paramiko->ansible)
Using cached enum34-1.1.6-py2-none-any.whl
Collecting ipaddress (from cryptography>=1.1->paramiko->ansible)
Using cached ipaddress-1.0.18-py2-none-any.whl
Collecting cffi>=1.4.1 (from cryptography>=1.1->paramiko->ansible)
Using cached cffi-1.10.0-cp27-cp27m-macosx_10_6_intel.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=1.1->paramiko->ansible)
Using cached asn1crypto-0.22.0-py2.py3-none-any.whl
Requirement already satisfied: pyparsing in ./ansible-test/lib/python2.7/site-packages (from packaging>=16.8->setuptools->ansible)
Collecting pycparser (from cffi>=1.4.1->cryptography>=1.1->paramiko->ansible)
Installing collected packages: pycrypto, idna, enum34, ipaddress, pycparser, cffi, asn1crypto, cryptography, pyasn1, paramiko, MarkupSafe, jinja2, PyYAML, ansible
Successfully installed MarkupSafe-1.0 PyYAML-3.12 ansible-2.3.0.0 asn1crypto-0.22.0 cffi-1.10.0 cryptography-1.8.1 enum34-1.1.6 idna-2.5 ipaddress-1.0.18 jinja2-2.9.6 paramiko-2.1.2 pyasn1-0.2.3 pycparser-2.17 pycrypto-2.6.1
Checked the version:
(ansible-test) zoidberg:foley chris$ ansible --version
ansible 2.3.0.0
config file =
configured module search path = Default w/o overrides
python version = 2.7.13 (default, May 14 2017, 22:38:03) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
Installed docker and docker-py:
(ansible-test) zoidberg:foley chris$ pip list | grep docker
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.
docker (2.0.0)
docker-py (1.10.6)
docker-pycreds (0.2.1)
But I still get the same error:
(ansible-test) zoidberg:foley chris$ ansible-playbook -i inventory/local build.yml -vvvv
No config file found; using defaults
Loading callback plugin default of type stdout, v2.0 from /Users/chris/src/hc/foley/ansible-test/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
PLAYBOOK: build.yml **********************************************************************************************************************************************************
1 plays in build.yml
PLAY [Build foley docker images] *********************************************************************************************************************************************
META: ran handlers
TASK [docker_image] **********************************************************************************************************************************************************
task path: /Users/chris/src/hc/foley/build.yml:12
Using module file /Users/chris/src/hc/foley/ansible-test/lib/python2.7/site-packages/ansible/modules/cloud/docker/docker_image.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: chris
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889 `" && echo ansible-tmp-1494837576.9-236428678313889="` echo /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889 `" ) && sleep 0'
<localhost> PUT /var/folders/zn/cfj4ng250293z1g5s19w3zdh0000gn/T/tmp_SRwg6 TO /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889/docker_image.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889/ /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889/docker_image.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889/docker_image.py; rm -rf "/Users/chris/.ansible/tmp/ansible-tmp-1494837576.9-236428678313889/" > /dev/null 2>&1 && sleep 0'
fatal: [127.0.0.1 -> localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_version": null,
"archive_path": null,
"buildargs": {
"PRIVATE_REPO_PASSWORD": "6c50ef3a91e9b5cd47251f921f3fb53d1e53afa5",
"PRIVATE_REPO_USERNAME": "hexagonalwax"
},
"cacert_path": null,
"cert_path": null,
"container_limits": null,
"debug": false,
"docker_host": null,
"dockerfile": null,
"filter_logger": false,
"force": false,
"http_timeout": null,
"key_path": null,
"load_path": null,
"name": "honeycomb/foley",
"nocache": "False",
"path": ".",
"pull": true,
"push": false,
"repository": null,
"rm": true,
"ssl_version": null,
"state": "present",
"tag": "latest",
"timeout": null,
"tls": null,
"tls_hostname": null,
"tls_verify": null,
"use_tls": "no"
}
},
"msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"
}
to retry, use: --limit @/Users/chris/src/hc/foley/build.retry
PLAY RECAP *******************************************************************************************************************************************************************
127.0.0.1 : ok=0 changed=0 unreachable=0 failed=1
Here's my playbook:
(ansible-test) zoidberg:foley chris$ cat build.yml
---
- name: Build foley docker images
hosts: 127.0.0.1
connection: local
gather_facts: false
vars_files:
- "ansible/vars/build_secrets.yml"
tasks:
- docker_image:
path: .
name: worldofchris/foley
buildargs:
PRIVATE_REPO_USERNAME: "{{ PRIVATE_REPO_USERNAME }}"
PRIVATE_REPO_PASSWORD: "{{ PRIVATE_REPO_PASSWORD }}"
delegate_to: localhost
And my inventory:
(ansible-test) zoidberg:foley chris$ cat inventory/local
[localhost]
127.0.0.1 ansible_connection=local
Any idea what I'm doing wrong?
Thanks
@worldofchris docker-py is older module, in ansible 2.3.0.0 try install only docker without docker-py:
pip uninstall docker
pip uninstall docker-py
pip install docker
and run your playbook.
If one install ansible from scratch in a clean centos environment, isn't Ansible supposed to bring the correct version of docker py or do we always need to run pip uninstall docker-py the first time?
@Applemann thanks for that. Tried your suggestion but get the same result:
(ansible-test) zoidberg:foley chris$ pip uninstall docker
Uninstalling docker-2.0.0:
...
Successfully uninstalled docker-2.0.0
(ansible-test) zoidberg:foley chris$ pip uninstall docker-py
Uninstalling docker-py-1.10.6:
...
Successfully uninstalled docker-py-1.10.6
(ansible-test) zoidberg:foley chris$ pip list | grep docker
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.
docker-pycreds (0.2.1)
(ansible-test) zoidberg:foley chris$ pip install docker
Collecting docker
Using cached docker-2.2.1-py2.py3-none-any.whl
Requirement already satisfied: backports.ssl-match-hostname>=3.5; python_version < "3.5" in ./ansible-test/lib/python2.7/site-packages (from docker)
Requirement already satisfied: ipaddress>=1.0.16; python_version < "3.3" in ./ansible-test/lib/python2.7/site-packages (from docker)
Requirement already satisfied: docker-pycreds>=0.2.1 in ./ansible-test/lib/python2.7/site-packages (from docker)
Requirement already satisfied: requests!=2.11.0,!=2.12.2,>=2.5.2 in ./ansible-test/lib/python2.7/site-packages (from docker)
Requirement already satisfied: websocket-client>=0.32.0 in ./ansible-test/lib/python2.7/site-packages (from docker)
Requirement already satisfied: six>=1.4.0 in ./ansible-test/lib/python2.7/site-packages (from docker)
Installing collected packages: docker
Successfully installed docker-2.2.1
(ansible-test) zoidberg:foley chris$ pip list | grep docker
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.
docker (2.2.1)
docker-pycreds (0.2.1)
(ansible-test) zoidberg:foley chris$ ansible-playbook -i inventory/local build.yml -vvvv
No config file found; using defaults
Loading callback plugin default of type stdout, v2.0 from /Users/chris/src/hc/foley/ansible-test/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
PLAYBOOK: build.yml **********************************************************************************************************************************************************
1 plays in build.yml
PLAY [Build foley docker images] *********************************************************************************************************************************************
META: ran handlers
TASK [docker_image] **********************************************************************************************************************************************************
task path: /Users/chris/src/hc/foley/build.yml:12
Using module file /Users/chris/src/hc/foley/ansible-test/lib/python2.7/site-packages/ansible/modules/cloud/docker/docker_image.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: chris
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324 `" && echo ansible-tmp-1494842343.37-265680192802324="` echo /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324 `" ) && sleep 0'
<localhost> PUT /var/folders/zn/cfj4ng250293z1g5s19w3zdh0000gn/T/tmph0iFSY TO /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324/docker_image.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324/ /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324/docker_image.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324/docker_image.py; rm -rf "/Users/chris/.ansible/tmp/ansible-tmp-1494842343.37-265680192802324/" > /dev/null 2>&1 && sleep 0'
fatal: [127.0.0.1 -> localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_version": null,
"archive_path": null,
"buildargs": {
"PRIVATE_REPO_PASSWORD": "6c50ef3a91e9b5cd47251f921f3fb53d1e53afa5",
"PRIVATE_REPO_USERNAME": "hexagonalwax"
},
"cacert_path": null,
"cert_path": null,
"container_limits": null,
"debug": false,
"docker_host": null,
"dockerfile": null,
"filter_logger": false,
"force": false,
"http_timeout": null,
"key_path": null,
"load_path": null,
"name": "honeycomb/foley",
"nocache": "False",
"path": ".",
"pull": true,
"push": false,
"repository": null,
"rm": true,
"ssl_version": null,
"state": "present",
"tag": "latest",
"timeout": null,
"tls": null,
"tls_hostname": null,
"tls_verify": null,
"use_tls": "no"
}
},
"msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"
}
to retry, use: --limit @/Users/chris/src/hc/foley/build.retry
PLAY RECAP *******************************************************************************************************************************************************************
127.0.0.1 : ok=0 changed=0 unreachable=0 failed=1
Have I followed your instructions correctly?
Cheers
Chris
@worldofchris you can also try run it with python3 interpreter instead of python 2.7
Because I was same problem here: https://github.com/ansible/ansible/issues/20492#issuecomment-293644891
And I solved it by run playbook under python3.
Thanks @Applemann switched it to Python 3 and it worked. I've needed a reason to move to Python 3 so this is as good a one as any.
Cheers!
Thanks @Applemann switching to python3 and pointing to the python interpreter in the virtualenv worked also.
ansible-playbook docker-test.yml \
-e 'ansible_python_interpreter=/data/python/envs/ansible/bin/python3'
Encountered this issue as well with
```
Python 2.7.13
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
ansible 2.3.0.0 (on local machine)
Client:
Version: 1.12.6
API version: 1.24
Go version: go1.7.4
Git commit: 78d1802
Built: Tue Mar 14 09:47:15 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Go version: go1.7.4
Git commit: 78d1802
Built: Tue Mar 14 09:47:15 2017
OS/Arch: linux/amd64
````
Setting python3
as executable didn't resolve this for me. Managed to get it working by doing a pip install docker docker-compose
(no docker-py
present) as suggested. Without docker-compose
via pip the docker_container
ansible module worked, docker_service
did not.
This has nothing to do with this issue. Ansible always required docker-compose for docker_service module.
Also, docker
and docker-py
are not coinstallable at the moment, so having both installed will probably cause issues.
It's now fixed in 2.3.0. You need just install latest docker-compose via pip on remote, then try to run it and it will tell you which old packages you need to delete.
Why this issue is still opened?
Still seeing this issue on Ansible 2.3.0:
$ ansible --version
ansible 2.3.0.0
config file = /vagrant/ansible/ansible.cfg
configured module search path = [u'./library']
python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
$ pip freeze | grep docker
docker==2.3.0
docker-compose==1.14.0
docker-pycreds==0.2.1
dockerpty==0.4.1
Playbook error with module docker_container
:
FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named docker. Try
pip install docker-py
"
OS: Ubuntu 14.04.5 with 3.13.0-121-generic x86_64 (vagrant box)
Python version: 2.7.6
EDIT: This is resolved by ensuring that the TARGET box has these pip modules installed, not just the box running ansible:
- name: Ensure old module not present
pip:
name: docker-py
state: absent
- name: Install pip modules on target box
pip:
name: "{{ item }}"
state: present
with_items:
- docker
- docker-compose
Still happens to me on ansible 2.3.1.0:
$ ansible --version
ansible 2.3.1.0
config file = /home/reegnz/demo/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
I am preparing a virtualenv only containing docker-compose, it pulls in docker as a transitive dependency.
$ virtualenv venv
$ source venv/bin/activate
(venv) $ pip install --upgrade pip
Downloading/unpacking pip from https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
Downloading pip-9.0.1.tar.gz (1.2MB): 1.2MB downloaded
Running setup.py egg_info for package pip
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Installing collected packages: pip
Found existing installation: pip 1.4.1
Uninstalling pip:
Successfully uninstalled pip
Running setup.py install for pip
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Installing pip script to /home/reegnz/test/venv/bin
Installing pip2.7 script to /home/test/venv/bin
Installing pip2 script to /home/test/venv/bin
Successfully installed pip
Cleaning up...
(venv) $ pip install docker-compose
Collecting docker-compose
Using cached docker_compose-1.14.0-py2.py3-none-any.whl
Collecting cached-property<2,>=1.2.0 (from docker-compose)
Using cached cached_property-1.3.0-py2.py3-none-any.whl
Collecting backports.ssl-match-hostname>=3.5; python_version < "3.5" (from docker-compose)
Collecting ipaddress>=1.0.16; python_version < "3.3" (from docker-compose)
Using cached ipaddress-1.0.18-py2-none-any.whl
Collecting jsonschema<3,>=2.5.1 (from docker-compose)
Using cached jsonschema-2.6.0-py2.py3-none-any.whl
Collecting texttable<0.9,>=0.8.1 (from docker-compose)
Collecting six<2,>=1.3.0 (from docker-compose)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting docker<3.0,>=2.3.0 (from docker-compose)
Using cached docker-2.4.0-py2.py3-none-any.whl
Collecting enum34<2,>=1.0.4; python_version < "3.4" (from docker-compose)
Using cached enum34-1.1.6-py2-none-any.whl
Collecting websocket-client<1.0,>=0.32.0 (from docker-compose)
Using cached websocket_client-0.44.0-py2.py3-none-any.whl
Collecting PyYAML<4,>=3.10 (from docker-compose)
Collecting colorama<0.4,>=0.3.7 (from docker-compose)
Using cached colorama-0.3.9-py2.py3-none-any.whl
Collecting requests!=2.11.0,<2.12,>=2.6.1 (from docker-compose)
Using cached requests-2.11.1-py2.py3-none-any.whl
Collecting docopt<0.7,>=0.6.1 (from docker-compose)
Collecting dockerpty<0.5,>=0.4.1 (from docker-compose)
Collecting functools32; python_version == "2.7" (from jsonschema<3,>=2.5.1->docker-compose)
Collecting docker-pycreds>=0.2.1 (from docker<3.0,>=2.3.0->docker-compose)
Using cached docker_pycreds-0.2.1-py2.py3-none-any.whl
Installing collected packages: cached-property, backports.ssl-match-hostname, ipaddress, functools32, jsonschema, texttable, six, websocket-client, docker-pycreds, requests, docker, enum34, PyYAML, colorama, docopt, dockerpty, docker-compose
Successfully installed PyYAML-3.12 backports.ssl-match-hostname-3.5.0.1 cached-property-1.3.0 colorama-0.3.9 docker-2.4.0 docker-compose-1.14.0 docker-pycreds-0.2.1 dockerpty-0.4.1 docopt-0.6.2 enum34-1.1.6 functools32-3.2.3.post2 ipaddress-1.0.18 jsonschema-2.6.0 requests-2.11.1 six-1.10.0 texttable-0.8.8 websocket-client-0.44.0
(venv) $ pip freeze > venv-requirements.txt
The venv-requirements.txt file looks like this:
( venv) $ cat venv-requirements.txt
backports.ssl-match-hostname==3.5.0.1
cached-property==1.3.0
colorama==0.3.9
docker==2.4.0
docker-compose==1.14.0
docker-pycreds==0.2.1
dockerpty==0.4.1
docopt==0.6.2
enum34==1.1.6
functools32==3.2.3.post2
ipaddress==1.0.18
jsonschema==2.6.0
PyYAML==3.12
requests==2.11.1
six==1.10.0
texttable==0.8.8
websocket-client==0.44.0
I install a virtualenv on my remote machine into /opt/ansible/venv with the pip requirements file above, and I override ansible_python_interpreter with the following script /opt/ansible/python-venv:
#!/bin/bash
source /opt/ansible/venv/bin/activate
python "$@"
I still get the following error from ansible-playbook:
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_version": null,
"build": false,
"cacert_path": null,
"cert_path": null,
"debug": false,
"definition": null,
"dependencies": true,
"docker_host": null,
"files": null,
"filter_logger": false,
"hostname_check": false,
"key_path": null,
"nocache": false,
"project_name": null,
"project_src": "/opt/test",
"pull": true,
"recreate": "smart",
"remove_images": null,
"remove_orphans": false,
"remove_volumes": false,
"restarted": false,
"scale": null,
"services": null,
"ssl_version": null,
"state": "present",
"stopped": false,
"timeout": 10,
"tls": null,
"tls_hostname": null,
"tls_verify": null
}
},
"msg": "Failed to import docker-py - No module named docker. Try `pip install docker-py`"
}
I also tried installing both docker-compose and docker-py packages to no avail. I still get the same error message then.
Turns out my quoted python-venv script was wrong and it works.
This was my script, not the one I quoted...
#!/bin/bash
source /opt/ansible/bin/activate
python "$@"
Notice missing 'venv' in the path.
Error message was not entirely clear, that's why it took me a while to debug. Json does not contain the python error message.
Sorry for the inconvenience.
ansible 2.3.0.0
python version = 2.7.13
$ pip list | grep docker
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.
docker (2.4.2)
docker-compose (1.14.0)
docker-pycreds (0.2.1)
dockerpty (0.4.1)
Error: FAILED! => {"changed": false, "failed": true, "msg": "Failed to import docker-py - No module named docker. Try pip install docker-py
"}
Pls suggest a solution for this. I am yet to try it on virtualenv , mentioned in reegnz comment.
For people lazy to read every post here:
Since ansible 2.3, the dependency issue docker-py is fixed:
if you use the default python 2.7, the docker module needs docker-py
if you use python 3 (-e 'ansible_python_interpreter=/usr/bin/python3'
), it needs docker instead of docker-py
in all case, clean by pip uninstall docker docker-py docker-compose
reinstall
pip install docker-compose
python 3 is not there in big distributions like CentOS/RHEL.
I would add, on top of @antoinetran that, with python 2.7, a one cannot have both: ansible and docker-compose happy.
-> ansible modules like docker & docker-login require docker-py
-> docker-compose require docker (and does not work if both docker and docker-py are installed):
docker-compose
WARNING: Dependency conflict: an older version of the 'docker-py' package may be polluting the namespace. If you're experiencing crashes, run the following command to remedy the issue:
pip uninstall docker-py; pip uninstall docker; pip install docker
So it's either ansible working or docker-compose. It's messy.
I am not clear why this issue is closed, as it looks ansible should update the modules to work with docker instead of docker-py, even for 2.7, like docker-compose did.
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 >>
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
Users keep running into this issue since one year. Why is this ticket closed?
Timo Soini
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. https://github.com/ansible/ansible/issues/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.
I was getting the error and running "pip install docker-py" fixed it, just as the error message said. Ansible 2.4.2.0.
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.
I am facing the issue in ansible==2.5.0
. Any help is highly appreciated.
Please try the resolution mentioned here https://github.com/ansible/ansible/issues/20492#issuecomment-361724244 - 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.
@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.
I started installing ansible with nix package manager to ensure it always
has the correct dependencies and no extra python libraries in the python
path. I agree this isn't an ansible problem, it's an upstream library
issue, but if state of your system is preventing ansible from working, nix
solves the problem very cleanly.
On Mon, Apr 2, 2018, 18:31 David Moreau Simard notifications@github.com
wrote:
@ryansb https://github.com/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.2Downgrading 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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ansible/ansible/issues/20492#issuecomment-378067072,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAnvxX5ctoUwDA-3VUVyTjh_k3vyMIa8ks5tkqbRgaJpZM4LpGqv
.
@ryansb Thank you for the help. But unfortunately it didn't fix the issue.
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
Please re-open this issue.
@jpiron do you have an updated status related to this?
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`"}
@lifenautjoe have you tried https://github.com/ansible/ansible/issues/20492#issuecomment-307642085
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.
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) ☹️
@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
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.
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.
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.
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.
Most helpful comment
docker-py is just the name of the project. It installs a python package named docker. So you should run:
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: