库存文件的 yml 格式...失败
yml format for inventory file...fails
---
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
基本上我有一个访问 s 并且到那个 s 有很多组 s 连接到它...已经尝试过“children “但这不起作用。一个典型的 ini 文件可以工作....
我还有一些变量...也适用于所有区域。访问 和组 ses...
将来会有超过 1 ..multiple access ses..
....
一些文档使用 ansible-host:...confusing..
是的..检查了 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'
第 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.xx
你有 yaml 缩进问题,这是一个错误(yaml 中的缩进很重要)。此外,您必须遵循 the specific format described in the documentation.
基本上,该文件是 parent/child 关系中的组的叠层,从顶部元素特殊组 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 any
var 定义(组中的 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"
]
}
}
---
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
基本上我有一个访问 s 并且到那个 s 有很多组 s 连接到它...已经尝试过“children “但这不起作用。一个典型的 ini 文件可以工作.... 我还有一些变量...也适用于所有区域。访问 和组 ses... 将来会有超过 1 ..multiple access ses.. .... 一些文档使用 ansible-host:...confusing..
是的..检查了 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'
第 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.xx
你有 yaml 缩进问题,这是一个错误(yaml 中的缩进很重要)。此外,您必须遵循 the specific format described in the documentation.
基本上,该文件是 parent/child 关系中的组的叠层,从顶部元素特殊组 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 any
var 定义(组中的 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"
]
}
}