Inventory looks like:
[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
I want to use ansible_host oh 'h2' in templates but I am getting ansible.errors.AnsibleUndefinedVariable error. How to resolve it?
I have already tried these:
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}}"