【发布时间】:2019-07-16 13:42:47
【问题描述】:
当我将主机的 ansible_python_interpreter 的值设置为 /usr/bin/python3 时,ansible-playbook 似乎仍在使用指向 python2.7 的 /usr/bin/python 我从输出显示的 -vvv 得到这个
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware_guest.py
我在我的 yml 文件中进行了调试,用于输出变量并返回:
"ansible_python_interpreter": "/usr/bin/python3"
ansible --version
ansible 2.8.2
config file = /ansible/automation/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-
packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5
20150623 (Red Hat 4.8.5-36)]
我已将库存文件中的位置转移为第一个变量,并将其添加为组变量,但没有任何乐趣。
当我使用 -e ansible_python_interpreter=/usr/bin/python3 运行 ansible-playbook 命令时,脚本运行正确
库存文件
[control]
<REDACTED HOST NAME> ansible_connection=local
ansible_python_interpreter=/usr/bin/python3
yml 摘录
---
- hosts: control
gather_facts: false
tasks:
- name: Debug a variable
debug:
var: ansible_python_intrepreter
- name: Clone a virtual machine from Windows template and customize
vmware_guest:
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
datacenter: some-datacenter
cluster: some-cluster
folder: "some-folder"
name: some-host
template: some-template
datastore: "some-datastore"
networks:
- name: some-network-name
ip: x.x.x.x
netmask: 255.255.255.0
gateway: x.x.x.x
mac: aa:bb:dd:aa:00:14
domain: domain.com
dns_servers:
- x.x.x.x
- x.x.x.x
进程运行时出现此错误 "无法在 Python /usr/bin/python2 上导入所需的 Python 库(请求)"
【问题讨论】:
标签: ansible ansible-2.x