为主机运行剧本时,如何访问该主机所属的所有组的所有组合变量?
例如如果有库存:
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 }}"