2016-05-23 10 views
0

Meine Host-Datei für ansible sieht wie untenAbrufen von Host-Informationen innerhalb jinja Vorlage

[deployment] 
server1 ansible_ssh_host=x.x.x.x ansible_ssh_user=root ansible_ssh_pass=abcdefg ansible_br_mgmt_ip=192.10.2.5 ansible_br_vlan_ip=192.10.4.5 ansible_br_vxlan_ip=192.10.8.5 
server2 ansible_ssh_host=y.y.y.y ansible_ssh_user=root ansible_ssh_pass=abcdefg ansible_br_mgmt_ip=192.10.2.6 ansible_br_vlan_ip=192.10.4.7 ansible_br_vxlan_ip=192.10.8.8 

Innen jinja-Vorlage (.j2 Datei) Ich versuche, den Wert von ansible_br_mgmt von Server 1 oder Server 2

abrufen

Ich versuchte die folgenden Möglichkeiten, aber konnte nicht die genaue IP-Adresse erhalten.

hostname: "{%  {{  hostvars['deployment'].ansible_br_mgmt_ip }} %}" 

hostvars.deployment.ansible_br_mgmt_ip 
groups['deployment'][ansible_br_mgmt_ip] 

können Sie bitte dabei helfen?

Antwort

0
- debug: msg={{ hostvars[groups['deployment'][0]].ansible_br_mgmt_ip }} 

Ausgang:

TASK: [debug msg={{ hostvars[groups['deployment'][0]].ansible_br_mgmt_ip }}] *** 
ok: [127.0.0.1] => { 
    "msg": "192.10.2.5" 
} 
Verwandte Themen