库存情况如下:
[host-1]
h1 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.d
h2 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.t
[host-2]
h3 ansible_ssh_private_key_file="*/*/*" ansible_host=a.b.c.r我希望在模板中使用ansible_host,噢,'h2‘,但是我收到了错误。如何解决这个问题?
我已经尝试过了:
1. "{{hostvars['host-2'][h2][ansible_host]}}"
2. "{{hostvars[host-2][h2][ansible_host]}}"
3. "{{hostvars['host-2'][h2].ansible_host}}"
4. "{{hostvars[groups['host-2'][h2]].ansible_host}}"发布于 2019-08-12 08:18:40
正确语法
"{{ hostvars['h2']['ansible_host'] }}",或者
"{{ hostvars.h2.ansible_host }}"提示:看看"{{ hostvars }}"和"{{ groups }}"。
发布于 2019-08-12 08:15:06
请把它当作一个提示:
- name: host
debug: msg="{{hostvars['h2']['ansible_host']}}"https://stackoverflow.com/questions/57457325
复制相似问题