【问题标题】:Syntax Error while loading YAML加载 YAML 时出现语法错误
【发布时间】:2017-10-22 09:12:22
【问题描述】:

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

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

但是当我启动请求这个角色的剧本时,我得到了这个错误:

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

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

【问题讨论】:

    标签: ansible yaml


    【解决方案1】:

    修复缩进:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多