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

19 views
Skip to first unread message

Irfan Sayed

unread,
Apr 11, 2018, 4:01:30 PM4/11/18
to Ansible Project

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,

Brian Coca

unread,
Apr 11, 2018, 5:56:52 PM4/11/18
to Ansible Project
`tasks:` should only appear in a play, not a tasks list for a role,
remove it and it should work.

--
----------
Brian Coca

Irfan Sayed

unread,
Apr 12, 2018, 6:46:54 AM4/12/18
to Ansible Project
Thanks. Got it :)
Reply all
Reply to author
Forward
0 new messages