Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
指向父级的Ansible库存组数组指针_Ansible_Ansible Inventory - Fatal编程技术网

指向父级的Ansible库存组数组指针

指向父级的Ansible库存组数组指针,ansible,ansible-inventory,Ansible,Ansible Inventory,我想看看是否有人知道我在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:children] clusterA[0] clusterB[0] 我不想重复web lb组中的IP地址,而是想执行以下操作:- [clusterA]

我想看看是否有人知道我在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:children]
clusterA[0]
clusterB[0]
我不想重复
web lb
组中的IP地址,而是想执行以下操作:-

[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: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]
clusterA[0]
clusterB[0]
但不是这个:

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

有关更多详细信息,请参阅Ansible和文档。Ansible非常灵活。您也可以使用
symbol将某些儿童从组中排除。

我确实尝试了您提到的方法,ansible似乎不理解,即使我们省略了组中的
children
标记。嗯。。。你知道为什么它会说当你的
hosts
文件是INI语法时,它会试图将其读取为YAML吗?当我在组中使用方括号时,这个错误就发生了。然后,我将
hosts
更改为
hosts.ini
并重试一次,我发现此错误
29286d512845:~$ansible-I hosts.ini all--列出主机错误!试图将“hosts.ini”读取为ini文件:主机范围必须是begin:end或begin:end:step
感谢您的快速响应。如果我正确理解ansible
清单
,则
模式
用法可以应用于主机,如
192.168.2.[100-110]
,但不能在组上使用。从
playbook
的角度来看,您可以应用组模式,如
hosts:clusterA[1]
。尽管如此,我已经放弃了这种方法,即我希望如何按照我在之前的帖子中所希望的方式来布局我的
清单
文件。它确实显示了相同的错误
主机范围必须是begin:end或begin:end:step
。我的结论是,你们不能给一个孩子或另一个群体本身的群体分配模式。您可以改为在主机上执行模式