2016-05-23 53 views
0

爲ansible我的主機文件看起來如下神社模板中檢索主機信息

[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 

內神社模板(.j2文件)我試圖檢索ansible_br_mgmt服務器1或服務器2

的價值

我嘗試了以下方法,但無法獲得確切的IP地址。

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

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

你能幫忙嗎?

回答

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

輸出:

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