【发布时间】:2019-10-18 12:07:01
【问题描述】:
我正在开发一个仍在运行 Python 2 的项目。我正在尝试使用 Ansible 设置新的测试服务器。我开始使用的基本 Linux 安装只有 Python 3,所以我需要我的第一个“引导”剧本来使用 Python 3,但随后我希望后续剧本使用 Python 2。
我可以像这样在我的清单文件中指定 python 的版本:
[test_server:vars]
ansible_python_interpreter=/usr/bin/python3
[test_server]
test_server.example.com
但是我必须去编辑库存文件以确保我使用 Python 3 作为引导剧本,然后为我的其余剧本再次编辑它。这似乎很奇怪。我在我的剧本中尝试了几个不同版本的更改ansible_python_interpreter,比如
- hosts: test_server
ansible_python_interpreter: /usr/bin/python
和
- hosts: test_server
tasks:
- name: install pip
ansible_python_interpreter: /usr/bin/python
apt:
name: python-pip
但是ansible抱怨说
错误! “ansible_python_interpreter”不是任务的有效属性
尽管https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html 这么说
您仍然可以将 ansible_python_interpreter 设置为任何变量级别的特定路径(例如,在 host_vars、vars 文件、playbooks 中等)。
正确执行此操作的调用是什么?
【问题讨论】:
标签: ansible