我想从我的模板中获取另一台主机。
鉴于以下情况hosts
file:
[vm]
vm_hostname
[monitoring]
monitoring_hostname
我怎样才能访问monitoring_hostname
从模板?
I tried:
monitor: {{ hostvars['monitoring'][0] }}
注意:我不能只使用monitor: monitoring_hostname
因为我的hosts
文件是动态生成的。
你想使用groups魔法变量 https://docs.ansible.com/ansible/latest/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts, not hostvars
:
monitor: "{{ groups['monitoring'][0] }}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)