加载YAML文件时出错
我试着运行这段代码加载YAML文件时出错,yaml,ansible,ansible-playbook,Yaml,Ansible,Ansible Playbook,我试着运行这段代码 --- - hosts: my-host - vsphere_guest: vcenter_hostname: vcenter.mydomain.local username: myuser password: mypass guest: newvm001 vmware_guest_facts: yes 但我一直在犯这个错误 错误!加载YAML时出现语法错误 该错误似乎已发生 “/Users/Desktop/Ansible/cre
---
- 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
有人能帮我解释一下发生了什么事吗?我可以试试。:-)写入-hosts:my host
时,将启动一个新列表,其中包含一个具有一个键值对的dict(hosts
,设置为字符串值)。然后YAML解析器看到-vsphere\u guest:
缩进了一个级别,它不太确定如何处理它。它无法将其嵌套在主机下,因为该主机已设置为字符串。它无法启动新列表,因为它已缩进。所以它失败了
我想你真正想要的是这样的:
---
- hosts: my-host
tasks:
- vsphere_guest:
vcenter_hostname: vcenter.mydomain.local
username: myuser
password: mypass
guest: newvm001
vmware_guest_facts: yes