【问题标题】:YAML syntax error (Ansible) using playbooks使用剧本的 YAML 语法错误 (Ansible)
【发布时间】:2019-08-22 18:39:07
【问题描述】:

我使用 ansible-module-vcloud,我想通过 Ansible 创建虚拟机。例如,我想创建最简单的剧本。

我有这个代码:

---

- name: vCloudDirectorAnsible
  hosts: localhost
  environment:
    env_user: admin
    env_password: admin
    env_host: vcloud.vmware.ru
    env_org: test
    env_api_version: 30.0
    env_verify_ssl_certs: false

- name: create catalog
  vcd_catalog:
        catalog_name: "test"
        catalog_description: "test_Descr"
        state: "present"

但我得到了错误:

ERROR! 'vcd_catalog' is not a valid attribute for a Play

The error appears to have been in '/root/ansible-module-vcloud-director/main.yml': line 14, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: create catalog
  ^ here

如果我删除这部分:

- name: create catalog
  vcd_catalog:
        catalog_name: "test"
        catalog_description: "test_Descr"
        state: "present"

我的剧本将运行并成功完成。

如何解决这个问题?

【问题讨论】:

    标签: linux centos ansible yaml


    【解决方案1】:

    您错过了 tasks 关键字。

    ---
    
    - name: vCloudDirectorAnsible
      hosts: localhost
      environment:
        env_user: admin
        env_password: admin
        env_host: vcloud.vmware.ru
        env_org: test
        env_api_version: 30.0
        env_verify_ssl_certs: false
      tasks:
        - name: create catalog
          vcd_catalog:
            catalog_name: "test"
            catalog_description: "test_Descr"
            state: "present"
    

    【讨论】:

    • 嗨!现在,我得到了这个错误:错误!加载 YAML 时出现语法错误。未找到预期的“-”指示符错误似乎出现在“/root/ansible-module-vcloud-director/main.yml”中:第 14 行,第 1 列,但可能在文件中的其他位置,具体取决于确切的语法问题。违规行似乎是:tasks: ^ here
    • @k0chan 如果它应该出现在env_verify_ssl_certs: false 之后当然不会起作用,那么您不能在 YAML 文件的根级别同时拥有序列项和映射键。请提供一个完整解决方案,其中包括 OPs ansible 文件的第一项(并通过检查器运行它,以确保它至少是有效的 YAML)。
    猜你喜欢
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    相关资源
    最近更新 更多