Get the hostname from the hosts file

2019-02-28 09:01发布

I would like to get another host from one of my templates.

Given the following hosts file:

[vm]
vm_hostname

[monitoring]
monitoring_hostname

How can I access monitoring_hostname from a template?

I tried:

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

NB: I can't just use monitor: monitoring_hostname because my hosts file is dynamically generated.

标签: ansible
1条回答
神经病院院长
2楼-- · 2019-02-28 09:26

You want to use groups magic variable, not hostvars:

monitor: "{{ groups['monitoring'][0] }}"
查看更多
登录 后发表回答