Ansible无法找到python模块 [英] Ansible not able to find python module

查看:43
本文介绍了Ansible无法找到python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ansible 在多个虚拟机上运行 docker swarm.
ansible 无法在远程机器上找到 python 模块 docker,即使它已经安装.

Using ansible to run docker swarm on multiple virtual machines.
The ansible is not able to find the python module docker on the remote machine, even though it has been installed.

运行剧本sudo ansible-playbook -i inv2.py/etc/ansible/playbook.yml

错误信息:

fatal: [10.212.137.216]: FAILED! => {"changed": false, "msg": "Failed to import docker or docker-py - No module named requests.exceptions. Try `pip install docker` or `pip install docker-py` (Python 2.6)"}

模块列表:

ubuntu@donald0:~$ pip list
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.
...
cryptography (2.1.4)
docker (3.7.1)
docker-pycreds (0.4.0)
...

推荐答案

出现此错误是因为 Ansible 正在搜索您正在使用的 Python 模块的不同路径.

This error occurs because Ansible is searching for a different path of the python modules that you are using.

当您使用 official package,它使用 Python 2.7,所以当你运行 Ansible 时,它​​会搜索 python 2 模块.

When you install Ansible using the official package, it uses Python 2.7, so when you run Ansible it will search for the python 2 modules.

有一些方法可以解决这个问题:

There are some ways to solve this:

- 添加 ansible_python_interpreter 选项以设置正确的 Python 路径:

- Adding the ansible_python_interpreter option setting your correct Python path:

就像下面的例子:

ansible-playbook -i inventory playbook.yml -e 'ansible_python_interpreter=/usr/bin/python3'

- 使用 pip3 重新安装 ansible:

使用以下命令:

sudo apt remove ansible
pip3 install ansible

我认为第二个选项是避免未来错误的最佳方法.

I think that the second option is the best approach to avoid future errors.

阅读有关 Ansible 对 Python 3 支持的更多信息:Ansible - Python 3 支持.

Read more about Python 3 Support with Ansible: Ansible - Python 3 Support.

这篇关于Ansible无法找到python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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