Ansible 如何从特定主机的资源清册中访问ip_地址?
清单如下所示:Ansible 如何从特定主机的资源清册中访问ip_地址?,ansible,ansible-inventory,ansible-template,Ansible,Ansible Inventory,Ansible Template,清单如下所示: [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\u主机oh
[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\u主机oh'h2但是我得到了ansible.errors.AnsibleUndefinedVariable错误。如何解决
我已经试过了:
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}}"
请把它当作一个提示:
- name: host
debug: msg="{{hostvars['h2']['ansible_host']}}"
请把它当作一个提示:
- name: host
debug: msg="{{hostvars['h2']['ansible_host']}}"
正确语法
"{{ hostvars['h2']['ansible_host'] }}"
,或
提示:查看“{{hostvars}}”和“{{groups}}”的正确语法
"{{ hostvars['h2']['ansible_host'] }}"
,或
提示:看一下“{{hostvars}}”
和“{{groups}}”