一台主机有多个组的变量

One host has vars of many groups

我有一个如下所示的清单文件:

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:  

在 group vars 文件夹中我有这个代码 hi.yml

services:
  - ls
  - pwd

bye.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] 的结果列表吗?

but i'm getting errors like:

我根据 copy-pasting 你的问题的内容制作了相同的文件,并且它在 Ansible 2.8 上没有任何错误。

also do you know if i have crossed variable meanings, like in this case([ls] and [ls, pwd]), will i get in result list of vars [ls,ls,pwd] or [ls,pwd]?

组变量将在解析您的库存时应用于主机。并替换具有相同名称的变量。因此,由于在您的清单中按字母顺序排列的最后一组是 "hi",您的主机将有 service = [ls, pwd].