处理yaml时出现语法错误

时间:2016-05-17 21:42:24

标签: yaml

我有以下yml:

  mongo:
    version: 2.6.9
    repo: http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/RPMS/
    maxconns: 40
      standalonedb_host: myhost0001.ab-xy.aws.com
      standalonedb_port: 8399
      standalonedb: "{{standalonedb_host}}:{{standalonedb_port}}"

我在standalonedb_host行上遇到语法错误。我做错了什么?

编辑:奇怪的是,如果我对standalonedb变量进行去缩进,则错误就会消失。如果我再次添加空格,则返回错误。

1 个答案:

答案 0 :(得分:1)

问题是你有一个键/值对嵌套在键/值对下,即standalonedb_host: myhost0001.ab-xy.aws.comstandalonedb_*配置的其余部分)嵌套在maxconns: 40下。< / p>

根据您的配置,以下任一项都可以解决问题:

  • 删除嵌套:

    mongo:
      version: 2.6.9
      repo: http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/RPMS/
      maxconns: 40
      standalonedb_host: myhost0001.ab-xy.aws.com
      standalonedb_port: 8399
      standalonedb: "{{standalonedb_host}}:{{standalonedb_port}}"
    
  • 删除maxconns中的值,以便standalonedb_*相关的哈希值成为maxconns键的值:

    mongo:
      version: 2.6.9
      repo: http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/RPMS/
      maxconns:
        standalonedb_host: myhost0001.ab-xy.aws.com
        standalonedb_port: 8399
        standalonedb: "{{standalonedb_host}}:{{standalonedb_port}}"