合并主机所属组中的所有变量

时间:2019-02-07 10:28:21

标签: 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运行一本剧本,然后获取organizationcountrycity的变量。

UPD

这是我访问剧本中变量的方式:

vars:
  organization: "{{ hostvars[inventory_hostname].vars.organization }}"
  country: "{{ hostvars[inventory_hostname].vars.country }}"
  city: "{{ hostvars[inventory_hostname].vars.city }}"

0 个答案:

没有答案
相关问题