加载YAML时出现语法错误 [英] Syntax Error while loading YAML

查看:195
本文介绍了加载YAML时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实有这样定义的角色foo:

I do have a role foo defined this way:

# roles/foo/tasks/main.yml
---
- name: restart Apache
    systemd:
      name: apache2
      state: restarted
      daemon_reload: yes

当我启动要求该角色的剧本时,却出现了以下错误:

bute when I start the playbook which requests this role then I get this error:

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/root/roles/foo/tasks/main.yml': line 4, column 12, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: restart Apache
    systemd:
           ^ here

我不明白这里出了什么问题,因为我在文档中找到了这样的示例...
(我省去了该角色定义的其他部分,并且运作良好)

I do not understand what is wrong here because I found such samples in the documentation...
(I left out the other parts which are defined in this role and are working well)

推荐答案

修复缩进:

---
- name: restart Apache
  systemd:
    name: apache2
    state: restarted
    daemon_reload: yes

我不明白这里出了什么问题,因为我在文档中找到了这样的示例...

I do not understand what is wrong here because I found such samples in the documentation...

YAML中的缩进对于解释很重要.某些元素必须在同一级别上定义.

Indentation in YAML is significant for interpretation. Certain elements must be defined at the same level.

请注意,systemd:行以冒号结尾,后跟一个缩进的块(整个块成为其值),而name:在同一行中定义了值restart Apache.

Notice that systemd: line ends with a colon and is followed by an indented block (where the whole block becomes its value), while name: has value restart Apache defined in the same line.

这篇关于加载YAML时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆