如何更改Ubuntu上的翻译员值?
我从tar下载并安装了Python2.7.12,现在默认情况下它在Ansible之外运行
# which python
/usr/local/bin/python#python --version
Python 2.7.12但是当我试图设置变量时,Ansible显示它仍然在使用新版本的Python (我需要使用这个旧版本来测试)
# ansible-playbook --version -e "ansible_python_interpreter=/usr/local/bin/python"
ansible-playbook 2.5.1
config file = /home/fortinet/Downloads/ansible/playbooks/complete_provisioning/ansible.cfg
configured module search path = [u'/home/fortinet/Downloads/ansible/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
root@ubuntu18:/home/fortinet/Downloads/ansible/playbooks/complete_provisioning#发布于 2020-06-20 06:42:59
不可能配置Ansible在控制器上使用的Python版本。
翻译员配置参数将设置:
用于在远程目标上执行模块的Python解释器的路径
Python在控制器上的版本取决于如何构建Ansible。例如
shell> grep DISTRIB_DESCRIPTION /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
shell> dpkg -l | grep ansible
ii ansible 2.9.6-1ppa~bionic
shell> ansible --version
ansible 2.9.6
config file = /home/admin/.ansible.cfg
configured module search path = [u'/home/admin/.ansible/my_modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]shell> grep DISTRIB_DESCRIPTION /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 20.04 LTS"
shell> dpkg -l | grep ansible
ii ansible 2.9.6+dfsg-1
shell> ansible --version
ansible 2.9.6
config file = /home/admin/.ansible.cfg
configured module search path = ['/home/admin/.ansible/my_modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Apr 27 2020, 15:53:34) [GCC 9.3.0]发布于 2020-06-20 06:42:26
ansible_python_interpreter控制在目标机器上使用的python版本。
在我的ubuntu18.04机器(用作目标的本地主机)上,默认使用python3,但我可以切换到python2.7:
$ 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
}现在,上面的示例显示了ansible在控制器上使用的python版本。如果要更改该版本,则必须在要使用的特定版本的python中重新安装ansible。这实际上取决于您如何安装ansible (rpm,deb,pip,从源.)。基本上,从python2.7到python3.x,在用pip安装时:
pip uninstall ansible
pip3 install ansiblehttps://stackoverflow.com/questions/62480949
复制相似问题