Ansible Python 解释器 - 找不到模块错误

问题描述 投票:0回答:1

我有一个为 Ansible playbook 编写的 main.yml 文件,我在其中调用 python 脚本。我的 ansible 版本是 2.9,默认的 python 脚本版本是 3.6.8 ..我导入了一些模块,如 NetmikoAuthentication 和 NetmikoTimeout 以及 SSH,但只有当我的 python 版本 >=3.8 且 < 4.0 … I have also upgraded my python to 3.8.9 which is shown in my /usr/local/bin/python3.8 … for my python script , I want to specifically call it using 3.8 but it is by far accepting the default python version 3.6 . How to resolve this issue ?? Can anyone help me out . I have even used vars section where I have used ansible_python_interpreter: “/usr/local/bin/python3.8 “ as my path as well . Still it is not accepting . Any responses will be highly appreciated .

时才可以接受

我尝试使用变量并添加了

  • 变量: ansible_python_interpreter:“/usr/local/bin/python3.8”

但它仍然只反映默认的 python 版本 3.6 …我期望我使用的这个 python 脚本应该反映版本 3.8 而不是 3.6 。

python-3.x ansible importerror
1个回答
0
投票

根据 ansible 文档,您应该在主机级别设置 python 解释器。

所以,在

hosts
文件上:

[myhosts]
host_1
host_2
...
host_n

[myhosts:vars]
ansible_python_interpreter=/path/to/python3.8

您还可以在

ansible.cfg
文件上设置默认的 python 解释器。

© www.soinside.com 2019 - 2024. All rights reserved.