Ansible cannot import docker, even if it is installed

I checked this post and followed the correction in both answers, and none of them worked. I am opening a new message partly because of this, and partly because I have a slightly different error, although the problem may be the same.

Strong host:

$ ansible --version ansible 2.1.0.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides 

Client-client-recipient:

 $ pip list | egrep 'six|docker|websocket_client' docker-py (1.2.3) six (1.10.0) 

test.yml:

 --- - hosts: myserver remote_user: root tasks: - name: stop any running docker registries docker_container: name: registry state: stopped ... 

An unrelated server (a playable player with an ap alias):

$ ap -vvvv test.yml

Exit:

(possibly extraneous output cut off):

 fatal: [myserver]: FAILED! => { "changed": false, "failed": true, "invocation": { "module_args": { "api_version": null, "blkio_weight": null, "cacert_path": null, "capabilities": null, "cert_path": null, "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, "etc_hosts": null, "exposed_ports": null, "filter_logger": false, "force_kill": false, "groups": null, "hostname": null, "image": null, "interactive": false, "ipc_mode": null, "keep_volumes": true, "kernel_memory": null, "key_path": null, "kill_signal": null, "labels": null, "links": null, "log_driver": "json-file", "log_options": null, "mac_address": null, "memory": "0", "memory_reservation": null, "memory_swap": null, "memory_swappiness": null, "name": "registry", "network_mode": null, "networks": null, "oom_killer": null, "paused": false, "pid_mode": null, "privileged": false, "published_ports": null, "pull": false, "read_only": false, "recreate": false, "restart": false, "restart_policy": null, "restart_retries": 0, "security_opts": null, "shm_size": null, "ssl_version": null, "state": "stopped", "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": 

(corresponding error):

"Failed to import docker-py - cannot import name NotFound. Try pip install docker-py"}

I get the same error when I lower the docker-py module to 1.1.0 according to the first answer in the specified article. I also tried chmod directories, and that didn't matter:

 (/usr/lib/python2.7/site-packages) myserver$ ls -lad docker* drwxr-xr-x. 6 root root 4096 Jul 4 10:57 docker/ drwxr-xr-x. 2 root root 4096 Jul 4 10:57 docker_py-1.2.3-py2.7.egg-info/ 

from chmod -R go+rx docker* .

Has anyone seen this before? I tried to use the AP module to install the modules, and then, removing them manually, reinstalled them manually, as in the link. I also use 2.1.0.0. as you can see, that was supposed to solve this problem.

+8
source share
4 answers

This is because newer versions of the python docker and docker-py modules that cannot be used are incompatible. I had to go back and explicitly specify the following versions of PIP packets:

  • docker: 2.0.0
  • docker-py: 1.10.6

An example task for this book:

 - name: install certain python modules for docker pip: name: "{{ item.name }}" version: "{{ item.version }}" state: present with_items: - { name: docker, version: 2.0.0 } - { name: docker-py, version: 1.10.6 } 

All of my game books have been working fine ever since.

+4
source

I have been given the path to docker-py .

 - hosts: <host> environment: PYTHONPATH: "/home/path/.local/lib/python2.7/site-packages" 

Basically Ansible was looking for the wrong directory.

Full credit to Clay Graham for his wonderful article on this subject:

https://medium.com/dronzebot/ansible-and-docker-py-path-issues-and-resolving-them-e3834d5bb79a

+4
source

The requirements for the docker-py module for the available documentation for docker * modules are actually not relevant, but, as a rule, there are several pairs-pairs-docker-programs that should work:

  • Ansible 2.1.0.0 requires at least docker-py version 1.7.0, which in turn requires a minimum of docker 1.9 on the client.

  • If you need to use an older version of dockers, you can use dock version 1.7 with available 2.0.1.0 and docker-py 1.4.0.

  • If you need an even older version of dockers, for example 1.6, then you are stuck with an incomparable 1.9

+1
source

TL DR

Do not use the --user flag for pip to install the docker module and then use -b or --become for ansible-playbook because an elevated instance of the playbook will not see the docker module that is installed for another user.


Looking back, it was probably obvious to everyone why I was --user with the problem, but for some reason I decided to install docker using the pip flag --user and then had a bad “idea” to use the -b or --become option.

This made the “apparently” installed docker module unavailable for the elevated Ansible instance on which my playbook is running. Exchange in case someone has “one of those days” and stumbles upon it later. Hope this helps you, as I paid for this reminder with a nice “dumb tax”, hope for both of us. :)

+1
source

All Articles