Ansible库存组数组指针父

问题描述:

我想检查是否有人知道是否有解决方案,我在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 

我不认为你可以使用: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