ansible - Ansible Inventory 文件优先级
问题描述
我一直在阅读vars
Ansible 中的优先级,但我不确定我得到的行为是否是设计使然。这是我的 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
期望的是,当访问. 但事实并非如此,所有虚拟机都设置为.worker-we-vm1
ip_prefix
10.60
scus
worker-scus-vm1
ip_prefix
10.61
hostvars
ip_prefix
10.60
谁能帮助理解为什么vars
优先级没有按预期工作?我已经阅读了https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html,它似乎与如何处理父变量和同级变量相矛盾。
解决方案
Ansible 主机组命名空间是扁平的,不是分层的,因此您的示例中只有一个workers
组。
当您为该组定义相同的变量两次时,只保留最后一个值。
workers
例如,将您的组拆分为workers_we
和workers_scus
(如果这是定义的原因,则使用主机模式)。
推荐阅读
- c++ - 如何将 const char* 转换为 char[256]
- r - 将 geom_area 中的区域调整为 geom_line 中的一条线
- node.js - 当我尝试将我的 Angular 应用程序部署到 heroku 时,在 multi ./src/styles.scss 中出现错误
- javafx - 在 PC 上运行时使用 Java FX 中的 Canvas 绘图非常模糊
- python - 打开 django suit 管理器时自动运行的操作
- python - 如何在经典asp网站上的python网络抓取应用程序中访问和解析源框架
- reactjs - ReactJS 如何处理具有大量组件的应用程序的内存?
- java - 如何获得任何 BigInteger 的先前素数?
- filter - 在 Google 表格中,公式可以在一个单元格中构建并在另一个单元格中激活吗?
- mysql - Codeigniter MySQL 不正确的日期时间插入