ansible - 一个主机有许多组的变量
问题描述
我有一个如下所示的库存文件:
all:
children:
win:
children:
hi:
hosts:
10.50.127.18:
10.50.127.19:
bye:
hosts:
10.50.127.18:
10.50.127.19:
linux:
children:
hi:
hosts:
10.50.127.20:
bye:
hosts:
10.50.127.20:
在组 vars 文件夹中,我有这个代码 hi.yml
services:
- ls
- pwd
再见.yml
services:
- pwd
然后在剧本中我有这个:
- hosts: linux
gather_facts: no
tasks:
- name: lalaland
command: "{{ item }}"
loop: "{{services}}"
但我收到如下错误:
fatal: [10.50.127.18]: FAILED! => {"msg": "Unexpected failure in finding the lookup named '{{services}}' in the available lookup plugins"}
你能告诉我我做错了什么吗?你也知道我是否有交叉变量含义,比如在这种情况下([ls] 和 [ls,pwd]),我会得到 vars [ls,ls,pwd] 或 [ls,pwd] 的结果列表吗?
解决方案
但我收到如下错误:
我通过从您的问题中复制粘贴它们的内容来制作相同的文件,并且它在 Ansible 2.8 上没有任何错误。
你也知道我是否有交叉变量含义,比如在这种情况下([ls] 和 [ls,pwd]),我会得到 vars [ls,ls,pwd] 或 [ls,pwd] 的结果列表吗?
解析库存时,组变量将应用于主机。并且替换同名的变量。因此,由于在您的库存中按字母顺序排列的最后一组是“hi”,因此您的主机将拥有service = [ls, pwd]
.
推荐阅读
- c# - NSubstitute Mock 静态类和静态方法
- java - 当我通过改造对象传递时收到空响应
- c# - 为什么这段代码会挂在`await TransformBlock.Completion`上
- swift - 如何在附加到 UITextField 的 UIPickerView 上设置 selectRow
- mrtk - 是否可以在构建中强制使用 MRTK 的 InputSimulationService?
- react-select - 移除对MouseOut React-Select 的关注
- memory - FPGA Stratix 3 存储器能否处理大量数据?
- javascript - Javascript函数计算自以来经过的年数
- python - Pandas 中的条件累积和
- c++ - 如何调用存储在数组中的数组的值