2016-08-05 60 views
0

我有以下inventory文件:提取服務器IP

[group_01] 
g01_h01   ansible_ssh_host='10.1.0.1' 
g01_h01   ansible_ssh_host='10.1.0.2' 

[group_02] 
g02_h01   ansible_ssh_host='10.2.0.1' 
g02_h01   ansible_ssh_host='10.2.0.2' 

[group_03:children] 
group_01 
group_02 

[group_03:vars] 
fst_group2={{groups['group_02'][0]}} 
snd_group1={{groups['group_01'][1]}} 

我想,在我的playbook變量有以下值:

fst_group2=10.2.0.1 
snd_group1=10.1.0.2 

相反,我得到:

fst_group2=g02_h01 
snd_group1=g01_h02 

任何想法,解決方法?

回答

0

很奇怪的任務的確...無論如何,

groups變量 - 是主機,這是g01_h01g01_h02,等的列表
爲了達到你所期望的,你可以使用這個:

[group_03:vars] 
fst_group2={{hostvars[groups['group_02'][0]]['ansible_ssh_host']}} 
snd_group1={{hostvars[groups['group_01'][1]]['ansible_ssh_host']}} 

請注意,ansible_ssh_host已棄用ansible_host