---
all:
zones:
- name: accessswitch
hosts:
- name: accessswitch-x0
ip: 192.168.4.xx
- name: groupswitch
hosts:
- name: groupswitch-x1
ip: 192.168.4.xx
- name: groupswitch-x2
ip: 192.168.4.xx
- name: groupswitch-x3
ip: 192.168.4.xx基本上,我有一个接入交换机,并且有许多组交换机已经连接到it...Tried“孩子”,但这不起作用。典型的ini文件可以工作...此外,我有一些variables...which确实适用于所有区域,又名。访问交换机和组开关...未来将有超过1台..multiple接入交换机。……有些文档使用ansible-host:...令人困惑..
和yes..checked的uml结构...
cat@catwomen:~/workspace/ansible-simulator/inventories/simulator/host_vars$ sudo ansible -i testdata.yaml all -m ping
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'
cat@catwomen:~/workspace/ansible-simulator/inventories/simulator/host_vars$ sudo ansible -i testdata.yaml all -m ping
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'发布于 2020-06-29 17:25:24
您有yaml缩进问题,这是一个错误( yaml中的缩进很重要)。此外,您必须遵循the specific format described in the documentation。
基本上,该文件是父/子关系中的组的叠加,从顶级元素特殊组all开始。组定义如下所示:
---
my_group1: # group name, use `all` at top level
vars:
# definition of vars for this group. Apply to all hosts if defined for `all`
hosts:
# hosts in that group (host is ungrouped if it appears only in `all`)
children:
# mapping of children group definitions (repeat the current format)主机定义如下所示:
my_host1:
# definition of vars specific to that host if anyvar定义(针对组中的vars或针对特定主机)如下所示:
my_variable1: some value如果我从您的示例中正确理解,以下是您的yaml清单应该是什么样子的(inventories/so_example.yml)
---
all:
children:
accessswitch:
hosts:
accessswitch-x0:
ansible_host: 192.168.4.xx
groupswitch:
hosts:
groupswitch-x1:
ansible_host: 192.168.4.xx
groupswitch-x2:
ansible_host: 192.168.4.xx
groupswitch-x3:
ansible_host: 192.168.4.xx然后,您可以很容易地看到上面的内容是如何用ansible-inventory command解释的
$ ansible-inventory -i inventories/so_example.yml --graph
@all:
|--@accessswitch:
| |--accessswitch-x0
|--@groupswitch:
| |--groupswitch-x1
| |--groupswitch-x2
| |--groupswitch-x3
|--@ungrouped:
$ ansible-inventory -i inventories/so_example.yml --list
{
"_meta": {
"hostvars": {
"accessswitch-x0": {
"ansible_host": "192.168.4.xx"
},
"groupswitch-x1": {
"ansible_host": "192.168.4.xx"
},
"groupswitch-x2": {
"ansible_host": "192.168.4.xx"
},
"groupswitch-x3": {
"ansible_host": "192.168.4.xx"
}
}
},
"accessswitch": {
"hosts": [
"accessswitch-x0"
]
},
"all": {
"children": [
"accessswitch",
"groupswitch",
"ungrouped"
]
},
"groupswitch": {
"hosts": [
"groupswitch-x1",
"groupswitch-x2",
"groupswitch-x3"
]
}
}发布于 2020-06-29 16:33:04
第6行的事件不正确。请在下面尝试。
---
all:
zones:
- name: accessswitch
hosts:
- name: accessswitch-x0
ip: 192.168.4.xx
- name: groupswitch
hosts:
- name: groupswitch-x1
ip: 192.168.4.xx
- name: groupswitch-x2
ip: 192.168.4.xx
- name: groupswitch-x3
ip: 192.168.4.xxhttps://stackoverflow.com/questions/62634065
复制相似问题