ansible中的系统特定变量

Aug*_*aas 24 ansible

Ansible期望python 2.在我的系统(Arch Linux)上,"python"是Python 3,所以我必须传递-e "ansible_python_interpreter=/usr/bin/python2"每个命令.

ansible-playbook my-playbook.yml -e "ansible_python_interpreter=/usr/bin/python2"
Run Code Online (Sandbox Code Playgroud)

ansible_python_interpreter在我的系统上是否有全局设置,所以我不必将它传递给每个命令?我不想将它添加到我的剧本中,因为并非所有运行剧本的系统都有类似于我的设置.

Dom*_*tro 31

那你可以用三种方式设置

  1. http://docs.ansible.com/intro_inventory.html#list-of-behavioral-inventory-parameters ansible_python_interpreter=/usr/bin/python2这将根据主机设置它
  2. 设置host_vars / ansible_python_interpreter: "/usr/bin/python2"这将为每个主机设置它
  3. 为文件中的所有节点设置它group_vars/all(您可能需要创建目录group_vars和文件all)ansible_python_interpreter: "/usr/bin/python2"

希望有所帮助

  • 我不希望它在剧本中的任何地方,这就是重点:)事实上我需要在我的机器上使用ansible python2特别不应该影响其他人使用剧本. (2认同)

Blu*_*hon 6

对于想要使用本地激活的 virtualenv python 解释器的人

inventory文件集中

[local]
localhost ansible_python_interpreter=python
Run Code Online (Sandbox Code Playgroud)


Tom*_*Tom 5

我选择使用 Ansible 从目录中获取库存的能力。通过这种方式,我可以ansible_python_interpreter仅为本地机器定义for localhost

inventory_dir/local

[local]
localhost ansible_python_interpreter="/path/to/alternate/bin/python"
Run Code Online (Sandbox Code Playgroud)

然后就像使用清单文件一样使用该目录。

ansible-playbook -i inventory_dir playbook.yml