首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >inventory file...fails的yml格式

inventory file...fails的yml格式
EN

Stack Overflow用户
提问于 2020-06-29 16:28:16
回答 2查看 84关注 0票数 1
代码语言:javascript
复制
---
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结构...

代码语言:javascript
复制
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'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-29 17:25:24

您有yaml缩进问题,这是一个错误( yaml中的缩进很重要)。此外,您必须遵循the specific format described in the documentation

基本上,该文件是父/子关系中的组的叠加,从顶级元素特殊组all开始。组定义如下所示:

代码语言:javascript
复制
---
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)

主机定义如下所示:

代码语言:javascript
复制
my_host1:
  # definition of vars specific to that host if any

var定义(针对组中的vars或针对特定主机)如下所示:

代码语言:javascript
复制
my_variable1: some value

如果我从您的示例中正确理解,以下是您的yaml清单应该是什么样子的(inventories/so_example.yml)

代码语言:javascript
复制
---
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解释的

代码语言:javascript
复制
$ 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"
        ]
    }
}
票数 2
EN

Stack Overflow用户

发布于 2020-06-29 16:33:04

第6行的事件不正确。请在下面尝试。

代码语言:javascript
复制
---
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62634065

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档