【问题标题】:Error while loading YAML file加载 YAML 文件时出错
【发布时间】:2023-04-02 06:00:01
【问题描述】:

我尝试运行这段代码

---
- hosts: my-host
  - vsphere_guest:
    vcenter_hostname: vcenter.mydomain.local
    username: myuser
    password: mypass
    guest: newvm001
    vmware_guest_facts: yes

但我不断收到此错误。

错误!加载 YAML 时出现语法错误。

错误似乎出现在 '/Users/Desktop/Ansible/createvms.yml':第 3 行,第 3 列, 但可能在文件中的其他位置,具体取决于确切的语法 问题。

违规行似乎是:

- hosts: my-host
  - vsphere_guest:   ^ here

有人可以帮忙解释一下发生了什么

【问题讨论】:

    标签: yaml ansible ansible-playbook


    【解决方案1】:

    我可以试试。 :-) 当你写- hosts: my-host 时,这会启动一个新列表,其中包含一个带有一个键值对的字典(hosts,它被设置为一个字符串值)。然后 YAML 解析器看到 - vsphere_guest: 缩进了一级,它不太确定如何处理它。它不能将它嵌套在hosts 下,因为它已经设置为字符串。它不能开始一个新的列表,因为它是缩进的。所以它失败了。

    我认为你真正想要的是这样的:

    ---
    - hosts: my-host
      tasks:
        - vsphere_guest:
            vcenter_hostname: vcenter.mydomain.local
            username: myuser
            password: mypass
            guest: newvm001
            vmware_guest_facts: yes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      相关资源
      最近更新 更多