Ansible Python 解释器问题

标签 ansible

我正在尝试将 Python 解释器更改为虚拟环境中的 Im。 但我也会在只有 python2 的 Jenkins 服务器上部署 venv。因此....

# grep python ansible/ansible.cfg
interpreter_python = ./venv/bin/python2

ansible --version | grep "python version"
  python version = 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]

我错过了什么?

最佳答案

检查 "Using Python3 on the managed machines with commands and playbooks"文档的一部分。该文章适用于 python3,但您最终使用哪个版本的 python 并不重要。在那篇文章中,您会看到这句话:

To explicitly configure a Python 3 interpreter, set the ansible_python_interpreter inventory variable at a group or host level to the location of a Python 3 interpreter, such as /usr/bin/python3. The default interpreter path may also be set in ansible.cfg.

因此,只需将 ansible_python_interpreter 设置为对您的 hosts 有意义的级别。

关于Ansible Python 解释器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57327133/

相关文章:

ansible - 检查进程是否正在运行

ansible - 从ansible中的变量key获取字典值

ansible - 如何根据变量获取别人的主机IP?

python - 安塞 bool + 10.11.6

python - 在ansible中,我们如何将所有任务文件包含在一个目录中

bash - ansible:远程机器上的文件是否有类似 with_fileglobs 的东西?

python - Ansible 模块条件要求

localhost - 当主机操作是带有ansible的本地主机时如何从组中排除本地主机

filter - 从 Ansible 变量中删除重复行

ansible - 如果任务的结果失败,changed_when 不工作