user3796292
user3796292

Reputation: 141

Error while loading YAML file

I try to run this piece of code

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

but I keep getting this error.

ERROR! Syntax Error while loading YAML.

The error appears to have been in '/Users/Desktop/Ansible/createvms.yml': line 3, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- hosts: my-host
  - vsphere_guest:   ^ here

Can someone please help explain what is happening

Upvotes: 1

Views: 3630

Answers (1)

mwp
mwp

Reputation: 8467

I can try. :-) When you write - hosts: my-host, this starts a new list containing a dict with one key-value pair (hosts, which is set to a string value). Then the YAML parser sees - vsphere_guest: indented one level and it's not quite sure what to do with it. It can't nest it under hosts because that's already set to a string. It can't start a new list because it's indented. So it fails.

I think what you really want is something like this:

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

Upvotes: 3

Related Questions