即使安装了dockerpy,Ansible也无法导入它(Ansible 2.3.0.0)

2024-10-01 13:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了与volvox相同的问题,他问了最初的问题,但在Ansible 2.3.0.0上,当我使用answerfrom{a3}中的建议时。在

复制步骤:

我创建了一个新的虚拟机:

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.

已安装的Ansible:

^{pr2}$

已检查版本:

(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)]

安装了此答案中建议的docker和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)

但我还是犯了同样的错误:

(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

这是我的剧本:

(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

我的库存:

(ansible-test) zoidberg:foley chris$ cat inventory/local
[localhost]
127.0.0.1 ansible_connection=local

你知道我做错什么了吗?在

谢谢


Tags: pathdockerpytestbuildsrclocalhostbin
1条回答
网友
1楼 · 发布于 2024-10-01 13:26:11

多亏了Ansible GitHub issues page上的Appleman我有了一个修复方法,它将与Python 3一起运行Ansible:

foley chris$ ansible-playbook -i inventory/local build.yml -e ansible_python_interpreter="/usr/local/bin/python3"

PLAY [Build foley docker images] ***********************************************************************************************************

TASK [docker_image] ************************************************************************************************************************
changed: [127.0.0.1 -> localhost]

PLAY RECAP *********************************************************************************************************************************
127.0.0.1                  : ok=1    changed=1    unreachable=0    failed=0

感谢techraf和{a4}对此的帮助。在

相关问题 更多 >