从hosts文件中获取主机名

时间:2018-02-12 19:08:16

标签: ansible

我想从我的一个模板中获取另一个主机。

给出以下hosts文件:

[vm]
vm_hostname

[monitoring]
monitoring_hostname

如何从模板访问monitoring_hostname

我试过了:

monitor: {{ hostvars['monitoring'][0] }}

注意:我不能只使用monitor: monitoring_hostname,因为我的hosts文件是动态生成的。

1 个答案:

答案 0 :(得分:2)

您想使用groups magic variable,而不是hostvars

monitor: "{{ groups['monitoring'][0] }}"