-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Comments
@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?
needs_info |
@guenhter |
@jctanner
|
@jpiron |
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. pip uninstall docker
pip uninstall docker-py
pip uninstall docker-compose
pip install docker-compose==1.9.0 |
@jpiron But IMO this is just a workaround to get things keep running. |
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?
|
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 e2a1ce2 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: |
This patch isn't present in Ansible |
I tried this today with
On the other hand, when
|
When will this be available in a release? |
Any news on this? |
As @viossat said, e2a1ce2 is included in the 2.3.0 version. 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" |
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 Original text - pre-edit: Just an update with some more info on a failing system. Mac 10.12.6 docker_image
|
I had the sample problem, Nothing mentioned in this thread helped. I downgraded ansible, and everything worked. |
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. #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. |
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.
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 |
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. |
@ryansb I am able to reproduce the issue with Ansible 2.5.0 on python3.
Despite:
Downgrading to Ansible 2.4.3.0 doesn't resolve the issue. 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 ***@***.***> 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.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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#20492 (comment)>,
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
|
Please re-open this issue. |
@jpiron do you have an updated status related to this? |
Went through the whole thread solutions, none worked.
|
@lifenautjoe have you tried #20492 (comment) |
If you've installed the In this case, you will need to set 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.
was breaking things for me. Here is my working environment:
Hope that helps. |
Still facing issues regarding this package in 2.5.3. When having When following the installation instructions provided by Ansible 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. |
ISSUE TYPE
COMPONENT NAME
docker_container
ANSIBLE VERSION
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:
python --version
Python 2.7.9
docker info
SUMMARY
When module
docker_container
is used, it fails every time withSTEPS TO REPRODUCE
EXPECTED RESULTS
Image is executed.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: