# Unexpected exception when including tasks from main.yml

**URL:** <https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915>\
**Category:** Ansible Project\
**Created:** [December 2, 2015, 8:42am UTC](https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915 "2015-12-02T08:42:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yongzhi\_Pan](https://avatars.discourse-cdn.com/v4/letter/y/edb3f5/32.png) [@Yongzhi\_Pan](https://forum.ansible.com/u/Yongzhi_Pan)\
**Post date:** [December 2, 2015, 8:42am UTC](https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915/1 "2015-12-02T08:42:07Z")

</div>

Ansible assumes that roles/x/tasks/main.yml is a plain list of tasks, but when the file is in the format:

tasks:

- xxx  
…

it fails with unexpected exception (AssertionError):

File “/opt/ansible/ansible/lib/ansible/playbook/helpers.py”, line 37, in load\_list\_of\_blocks  
assert isinstance(ds, (list, type(None)))  
AssertionError

When it expects ds to be an list, it is actually an dict with ‘task’ key.

It involves digging into the Ansible code to know that my main.yml is malformed. I would suggest Ansible point out the syntax, or accept both format of main.yml.

In either case, I would like to send a patch for review.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 2, 2015, 4:06pm UTC](https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915/2 "2015-12-02T16:06:46Z")

</div>

the assumption is correct, what is incorrect is your usage of 'tasks:'  
in this file, the message can be made clearer though.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 2, 2015, 4:11pm UTC](https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915/3 "2015-12-02T16:11:21Z")

</div>

Also, having the full traceback would be helpful.

All of those AssertionError exceptions should be caught, and the proper AnsibleParserError should be raised instead.

The catching of AssertionError should be happening in all locations where load\_list\_of\_blocks, load\_list\_of\_tasks and load\_list\_of\_roles is being used.

I was unable to find any place where the AssertionError is not being caught in current devel.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 2, 2015, 4:15pm UTC](https://forum.ansible.com/t/unexpected-exception-when-including-tasks-from-main-yml/19915/4 "2015-12-02T16:15:47Z")

</div>

So updated via c1add8c5e4758d2edea6e49c1b62aee614f5c4fb which now  
captures the assertion error and gives out something a bit more  
helpful.
