即使安装了 docker-py,Ansible 也无法导入 [英] Ansible cannot import docker-py even though it is installed

查看:26
本文介绍了即使安装了 docker-py,Ansible 也无法导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了这篇文章并按照两个答案都没有奏效.我打开一个新帖子部分是因为这个,部分是因为我得到了一个稍微不同的错误,即使问题可能是相同的.

I checked this post and followed the fix in both answers and neither worked. I'm opening a new post partly because of that and partly because I'm getting a slightly different error even though the problem might be the same.

Ansible 主机:

Ansible host:

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

目标客户端 myserver:

Destination client myserver:

$ 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
...

Ansible 服务器(ansible-playbook 别名为 ap):

Ansible server (ansible-playbook aliased to ap):

$ ap -vvvv test.yml

输出:

(可能是无关输出,被剪掉):

(probably extraneous output, snipped):

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": 

(相关错误):

无法导入 docker-py - 无法导入名称 NotFound.尝试 pip install docker-py"}

当我按照参考文章中的第一个答案将 docker-py 模块降级到 1.1.0 时,我遇到了同样的错误.我还尝试修改目录,但没有任何区别:

I get the same error when I downgrade the docker-py module to 1.1.0 as per the first answer in the referenced post. I also tried to chmod the directories and it made no difference:

(/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/

来自 chmod -R go+rx docker*.

有人见过这个吗?我曾尝试使用 pip ansible 模块来安装模块,然后在手动删除它们后,按照引用的帖子手动重新安装它们.我也在使用 2.1.0.0.如您所见,这应该可以解决此问题.

Has anyone seen this before? I have tried using the pip ansible module to install the modules and then after removing them manually, reinstalled them manually as in the referenced post. I'm also using 2.1.0.0. as you can see, which was supposed to fix this issue.

推荐答案

这是因为 ansible 使用的 Python 模块 dockerdocker-py 的新版本不兼容.我不得不回退并明确指定以下版本的 PIP 包:

This is because new versions of python modules docker and docker-py that ansible uses are incompatible. I had to revert back and explicitly specify the following versions of PIP packages:

  • 码头工人:2.0.0
  • docker-py: 1.10.6

这些的示例剧本任务:

- 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 my play books work fine since then.

这篇关于即使安装了 docker-py,Ansible 也无法导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆