擅长:python、mysql、java
<p><code>ansible_python_interpreter</code>控制在目标机器上使用的python版本</p>
<p>例如,在我的ubuntu 18.04机器(localhost用作目标)上,默认情况下使用python3,但我可以切换到python 2.7:</p>
<pre><code>$ ansible localhost -m setup -a filter=ansible_python_version
localhost | SUCCESS => {
"ansible_facts": {
"ansible_python_version": "3.6.9"
},
"changed": false
}
$ ansible localhost -m setup -e ansible_python_interpreter=/usr/bin/python -a filter=ansible_python_version
localhost | SUCCESS => {
"ansible_facts": {
"ansible_python_version": "2.7.17"
},
"changed": false
}
</code></pre>
<p>现在,上面的示例显示了ansible在<strong>控制器上使用的python版本。如果要更改该版本,必须在要使用的特定python版本中重新安装ansible。这实际上取决于您如何安装ansible(rpm、deb、pip,来自源代码…)。基本上,在安装pip时从python 2.7过渡到python 3.x:</p>
<pre><code>pip uninstall ansible
pip3 install ansible
</code></pre>