ansible - 合并主机所属组中的所有变量
问题描述
为主机运行剧本时,如何访问该主机所属所有组的所有组合变量?
例如,如果有库存:
all:
hosts:
somehost.acme.com
someotherhost.acme.com
vars:
organization: Acme Inc.
us:
hosts:
somehost.acme.com
vars:
country: US
city: New York
netherlands:
hosts:
someotherhost.acme.com
vars:
country: NL
city: Amsterdam
..我为主机运行一个剧本,然后somehost.acme.com
我会得到 和 的变量。organization
country
city
UPD
这就是我访问剧本中变量的方式:
vars:
organization: "{{ hostvars[inventory_hostname].vars.organization }}"
country: "{{ hostvars[inventory_hostname].vars.country }}"
city: "{{ hostvars[inventory_hostname].vars.city }}"
解决方案
推荐阅读
- asp.net-core - 如何在 .Net Core 中制作类模型?
- kotlin - 在 Kotlin 中计算 MutableMap 中的字符串出现次数
- python - 如何从熊猫数据框中组织 JSON 数据
- swift - 更新值时 UISlider 口吃
- python - 线程 'Thread-1' 中没有当前事件循环
- animation - Vue 3 项目中简单的路由器滑动过渡
- crystal-reports - 每当我拖动 Crystal Report Viewer 以显示表单时,它会下降而不从视图中显示
- arrays - 为什么每个值都没有初始化为 0?
- perl - 用于 DNA 序列反向互补的 Perl 代码
- asp.net-core - .Net Core 服务器端模型验证通过不显眼的 ajax 表单