Ansible error : ERROR! The tasks/main.yml file for role 'xyz' must contain a list of tasks

Hello,
i have following simple YAML play file

 ---
 tasks:
 - name: Execute the command in remote shell; stdout goes to the specified file on the remote.
   shell: echo hi

but when running ansible-playbook command: getting following error

ERROR! The tasks/main.yml file for role ‘xyz’ must contain a list of tasks

The error appears to have been in ‘/home/cdkubemaster1/plabook_structure/roles/xyz/tasks/main.yml’: line 2, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


tasks:
^ here

exception type: <type ‘exceptions.AssertionError’>
exception: {u’tasks’: [{u’shell’: u’echo hi’, u’name’: u’Execute the command in remote shell; stdout goes to the specified file on the remote.'}]} should be a list or None but is <class ‘ansible.parsing.yaml.objects.AnsibleMapping’>

what is expected:
All the tasks mentioned in the playbook should be executed …
i have here just one tasks , but the error says , need to have all the list of tasks …
Not getting what is mean to that ?
please suggest

Regards,

`tasks:` should only appear in a play, not a tasks list for a role,
remove it and it should work.

Thanks. Got it :slight_smile: