我有python2.7
和python3.5
在我的ansible
服务器中,同时执行它正在使用的剧本python2.7
。我想在执行剧本时ansible
使用python3.5
。
in order:
1 have set export path.
2 also changed default interpreter path in ansible.cfg as well.
3 have given specific interpretor path in hostsfile for particular host.
Run Code Online (Sandbox Code Playgroud)
但是,仍然ansible
没有运行python3
。
1) 有ANSIBLE_PYTHON_INTERPRETER配置参数需要设置:
用于在远程目标上执行模块的 Python 解释器的路径
2)控制器上的 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]
Run Code Online (Sandbox Code Playgroud)
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]
Run Code Online (Sandbox Code Playgroud)
sheel> uname -a
FreeBSD master.example.com 12.1-RELEASE FreeBSD 12.1-RELEASE r354233 GENERIC amd64
shell> pkg info | grep ansible
py27-ansible-2.8.5 Radically simple IT automation
py36-ansible-2.8.5 Radically simple IT automation
shell> ansible --version
ansible 2.8.5
config file = /home/admin/.ansible.cfg
configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/local/share/py36-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.9 (default, Nov 14 2019, 01:16:50) [GCC 4.2.1 Compatible FreeBSD Clang 6.0.1 (tags/RELEASE_601/final 335540)
Run Code Online (Sandbox Code Playgroud)
如果要为单个主机和组设置 Python 解释器,请设置ansible_python_interpreter
库存变量。
但是,如果您想将 Python 解释器设置为全局使用,则在配置文件interpreter_python
的[defaults]
部分中设置密钥ansible.cfg
。
有关上述两个选项的可能值的完整列表,请参阅:https : //docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html
另请参阅此示例以了解以下内容的用法ansible_python_interpreter
:https : //docs.ansible.com/ansible/2.4/python_3_support.html,“测试 Python 3 模块支持”部分。