Ansible roles formatting ERROR! Syntax Error while loading YAML

Ansible roles formatting

ansible-playbook -i env/dev web.yml 
ERROR! Syntax Error while loading YAML

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

The offending line appears to be:

    - rolesForDoX
   - rolesForDoY
      ^ here

Solution: you will get such issue, if your roles not properly place with same space along with “–“.

Note correct formatted web.yml
web.yml

---

- hosts: localhost
  connection: local
  gather_facts: no

  roles:
    - rolesForDoX
   - rolesForDoY
   - rolesForDoZ

Correct formatted web.yml
web.yml

---

- hosts: localhost
  connection: local
  gather_facts: no

  roles:
   - rolesForDoX
   - rolesForDoY

   - rolesForDoZ

Run now you will get success:

ansible-playbook -i env/dev web.yml

PLAY RECAP ****************************************************************

localhost                  : ok=3    changed=3    unreachable=0    failed=0

No comments:

Post a Comment