2016-08-31 55 views
1

我尝试运行这段代码加载时出错YAML文件

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

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

回答

3

我可以试试。 :-)当您编写- 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