python - Ansible pip virtualenv 安装失败,缺少 setuptools
问题描述
我发现了很多与 ansible pip + virtualenv 相关的文章/问题,但没有什么能让我感到困惑:
试图用 python 设置一个“简单”的 virtualenv,这个任务完全失败了:
---
- hosts: local
connection: local
tasks:
- name:
apt:
pkg:
- python3
- python3-pip
- python3-setuptools
- virtualenv
- name: Install some pip packages in virtualenv
pip:
name: requests
virtualenv: /opt/somevenv
virtualenv_python: python3
virtualenv_site_packages: yes
这导致
root@my-pc:/some/path# ansible-playbook test.yaml
PLAY [local] *****************************************************************************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [apt] *******************************************************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [Install some pip packages in virtualenv] *******************************************************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No setuptools found in remote host, please install it first."}
to retry, use: --limit @/some/path/test.retry
PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1
在当前安装了 python 3.7.3 并且使用 python3 的 Debian 10 上
root@my-pc:/some/path# ansible-playbook --version
ansible-playbook 2.7.7
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
pip3 也正确安装了 setuptools:
root@my-pc:/some/path# pip3 show setuptools
Name: setuptools
Version: 40.8.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
Location: /usr/lib/python3/dist-packages
Requires:
Required-by:
此外,python3 的使用是强制的:
root@my-pc:/some/path# tail -n3 /etc/ansible/ansible.cfg
# context = 3
[py3-hosts:vars]
ansible_python_interpreter=/usr/bin/python3
有人知道它为什么会失败吗?
奇怪的是,当做一个
# apt install python-setuptools
一切正常......我真的不明白为什么在后台以某种方式使用python2,尽管python3甚至设置为ansible。
解决方案
推荐阅读
- javascript - 将 cURL 命令转换为 http put 请求
- html - [HTML][Express] 在终端中使用 npm start 时应用程序崩溃
- javascript - Flask 应用程序:将 json 发布到服务器以在不同的 REST API 中使用
- mysql - 绑定参数需要一个值
- php - 表单仅在提交时编辑 Laravel 中的第一个 Id
- node.js - 打字稿节点 MODULE_NOT_FOUND
- python - 函数内的百分比格式
- imagemagick - ImageMagick - 转换:没有定义图像 `.png' @ error/convert.c/ConvertImageCommand/3322
- ios - UIDatePicker 上的 UITapGestureRecognizer 在 ios 15 中不起作用
- javascript - Jquery 'each' 等待 ajax 进程完成然后继续循环