Ansible python 版本不会改变 [英] Ansible python version won't change
问题描述
我正在执行:
ansible-playbook --version
我得到以下输出:
ansible-playbook 2.5.14
config file = /etc/ansible/ansible.cfg
configured module search path = [u'~/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
但是当我执行时:
ansible-playbook --version -e 'ansible_python_interpreter=/usr/bin/python3'
我有完全相同的输出.我期待有类似的东西:
I'm having exactly the same output. I was expecting having something like:
python version = 3.5.2
我误解了什么?
推荐答案
要更改托管主机上使用的 Python 解释器,您可以根据您的问题使用额外变量或库存变量.这不会更改用于在本地执行 ansible 的 python 版本 - 这在另一个答案中提到.
To change the python interpreter used on a managed host you can either use an extra or inventory variable, as per your question. This does not change the version of python used to execute ansible locally - which is mentioned in the other answer.
要确认您在托管主机上使用不同的解释器,您将需要更详细的输出(至少 3 个 'v's,-vvv
).在 shell 命令中运行 python --version
只会告诉你系统的默认 python 版本是什么.
To confirm that you are using a different interpreter on the managed host, you will need more verbose output (at least 3 'v's, -vvv
). Running python --version
in a shell command is just going to show you what the system's default python version is.
示例
Python2 解释器:
Python2 interpreter:
$ ansible localhost -a 'python --version' -e 'ansible_python_interpreter=/usr/bin/python2' -vvv
ansible 2.8.1
<snip>
python version = 3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
<snip>
'/bin/sh -c '"'"'/usr/bin/python2 /home/mattp/.ansible/tmp/ansible-tmp-1564023345.0848873-106174541151316/AnsiballZ_command.py && sleep 0'"'"''
<snip>
localhost | CHANGED | rc=0 >>
Python 2.7.16
Python3 解释器:
Python3 interpreter:
$ ansible localhost -a 'python --version' -e 'ansible_python_interpreter=/usr/bin/python3' -vvv
ansible 2.8.1
<snip>
python version = 3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
<snip>
'/bin/sh -c '"'"'/usr/bin/python3 /home/mattp/.ansible/tmp/ansible-tmp-1564023350.3869421-223113472194736/AnsiballZ_command.py && sleep 0'"'"''
<snip>
localhost | CHANGED | rc=0 >>
Python 2.7.16
关键要点
- 用于在本地运行 Ansible 的 Python 版本保持不变
- 系统默认python版本保持不变
- 用于远程执行 Ansible 命令模块的 python 版本(即 python 解释器)已从版本 2 更改为 3
这篇关于Ansible python 版本不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!