尝试使用GNS3练习ansible脚本,有一个内置ansible的名为“Network Automation”的docker实例。但是,它仍然使用 Python 2.7 作为解释器:
root@Network-Automation:~# ansible --version
ansible 2.7.11
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.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
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’”命令运行带有 Python 版本 3 的剧本,或者我可以在剧本中指定 var:
- name: Common package
hosts: all
gather_facts: no
vars:
ansible_python_interpreter: /usr/bin/python3
roles:
- { role: python, tags: [ init, python, common, addusers] }
...
...
但是,我想有一个永久的方法来强制 ansible 使用 Python3 版本。我怎样才能做到这一点?谢谢。
原文由 Cook 发布,翻译遵循 CC BY-SA 4.0 许可协议
为什么不在您的角色中使用 var 目录…
在 vars/main.yml 中添加….