gpt4 book ai didi

python - 即使已安装Ansible也无法导入docker-py(Ansible 2.3.0.0)

转载 作者:行者123 更新时间:2023-12-02 21:22:22 25 4
gpt4 key购买 nike

我遇到的volvox遇到了同样的问题,后者曾提出原始问题,但当我使用answeranoxis到他的帖子中的建议时,却遇到了Ansible 2.3.0.0。

重现步骤:

我创建了一个新的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.

已安装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

检查版本:
(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

知道我在做什么错吗?

谢谢

最佳答案

多亏了Appleman上的Ansible GitHub issues page,我对此有了一个解决方案,该解决方案可以在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

感谢 techrafKonstantin Suvorov在此方面的帮助。

关于python - 即使已安装Ansible也无法导入docker-py(Ansible 2.3.0.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43977815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com