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

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

问题描述

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

# roles/foo/tasks/main.yml---- 名称:重启Apache系统:名称:apache2状态:重启daemon_reload: 是

但是,当我启动要求此角色的剧本时,我收到此错误:

错误!加载 YAML 时出现语法错误.错误似乎在/root/roles/foo/tasks/main.yml"中:第 4 行,第 12 列,但可能根据确切的语法问题位于文件中的其他位置.违规行似乎是:- 名称:重启Apache系统:^ 这里

我不明白这里有什么问题,因为我在文档中发现了这样的示例...
(我省略了在这个角色中定义的并且运行良好的其他部分)

解决方案

修复缩进:

---- 名称:重启Apache系统:名称:apache2状态:重启daemon_reload: 是

<块引用>

我不明白这里有什么问题,因为我在文档中发现了这样的示例...

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

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

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)

解决方案

Fix indentation:

---
- 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...

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

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天全站免登陆