2017-09-13 99 views
1

我想檢查是否有人知道是否有解決方案,我在Ansible面臨的這個問題。Ansible庫存組數組指針父

我有一個清單文件看起來像這樣: -

[clusterA] 
10.0.0.1 
10.0.0.2 
10.0.0.3 
.... 

[clusterB] 
10.1.0.1 
10.1.0.2 
10.1.0.3 
.... 

[web-lb] 
10.0.0.1 
10.1.0.1 

而是在web-lb組重複的IP地址,我想要做這樣的事情: -

[web-lb:children] 
clusterA[0] 
clusterB[0] 

如果我們可以如上所述腳本組,我不需要重複IP地址,我可以將組中的不同項目混合到另一個組中,例如

[webA-lb:children] 
clusterA[1] 
clusterA[5] 
clusterB[3] 

修訂

具有以下配置不工作,以及

[webA-lb] 
clusterA[1] 

錯誤:

bbed5901ea74:~$ ansible -i hosts all --list-hosts 
hosts (6): 
10.1.0.1 
10.1.0.2 
10.1.0.3 
10.0.0.1 
10.0.0.2 
10.0.0.3 
bbed5901ea74:~$ vi hosts 
bbed5901ea74:~$ ansible -i hosts all --list-hosts 
ERROR! Attempted to read "hosts" as YAML: Syntax Error while loading YAML. 


The error appears to have been in '/home/jenkins/hosts': line 2, column 1, 
but may be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

[clusterA] 
10.0.0.1 
^ here 

Attempted to read "hosts" as ini file: host range must be begin:end or 
begin:end:step 

回答

0

我不認爲你可以使用:children結合的個人選擇[]就是這樣。後綴:children表示一組組。有關詳細信息,

[web-lb:children] 
clusterA[0] 
clusterB[0] 

見Ansible的PatternsInventory文檔:

所以,你可以這樣做:

[web-lb] 
clusterA[0] 
clusterB[0] 

但不是這個。 Ansible非常靈活。您還可以使用!符號從組中排除某些孩子。

+0

我確實嘗試過你提到的方法,而且即使我們省略了組中的「children」標籤,ansible也不明白。 – jlim

+1

嗯...你知道爲什麼它說它試圖讀取你的'主機'文件作爲YAML時,它的INI語法? – freginold

+1

在組中有方括號的那一刻,發生了這個錯誤。然後我把'hosts'改爲'hosts.ini',然後再試一次,我得到了這個錯誤:'29286d512845:〜$ ansible -i hosts.ini all --list-hosts 錯誤!試圖讀取「hosts.ini」作爲ini文件:主機範圍必須是開始:結束或開始:結束:步驟# – jlim