【发布时间】:2018-06-25 09:47:34
【问题描述】:
我一直在阅读 Ansible 中的 vars 优先级,但我不确定我得到的行为是否是设计使然。这是我的 Ansible 清单;
---
all:
children:
we:
children:
workers:
hosts:
worker-we-vm1:
order: 1
worker-ew-vm2:
order: 2
vars:
size: "Standard_B2s"
controllers:
hosts:
controller-we-vm:
order: 1
vars:
size: "Standard_B1s"
vars:
ip_prefix: "10.60"
scus:
children:
workers:
hosts:
worker-scus-vm1:
order: 1
worker-scus-vm2:
order: 2
vars:
size: "Standard_B2s"
vars:
ip_prefix: "10.61"
vars:
azure_profile: "test"
现在我期望we VM(例如worker-we-vm1)将ip_prefix 设置为10.60,而scus VM(例如worker-scus-vm1)将设置ip_prefix访问hostvars 时发送至10.61。但事实并非如此,所有虚拟机都将ip_prefix 设置为10.60。
谁能帮助理解为什么vars 优先级没有按预期工作?我读过https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html,它似乎与父变量和同级变量的处理方式相矛盾。
【问题讨论】: