diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index 4b29e8b74f..c4f11c1c8e 100644 --- a/lib/ansible/playbook/helpers.py +++ b/lib/ansible/playbook/helpers.py @@ -34,10 +34,7 @@ def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=Non # we import here to prevent a circular dependency with imports from ansible.playbook.block import Block - try: - assert isinstance(ds, (list, type(None))) - except AssertionError: - raise AnsibleParserError("Task list is not a list, invalid format provided: %s" % ds) + assert isinstance(ds, (list, type(None))) block_list = [] if ds: diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index 9d65639785..3cb914689f 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -171,11 +171,17 @@ class Role(Base, Become, Conditional, Taggable): task_data = self._load_role_yaml('tasks') if task_data: - self._task_blocks = load_list_of_blocks(task_data, play=self._play, role=self, loader=self._loader) + try: + self._task_blocks = load_list_of_blocks(task_data, play=self._play, role=self, loader=self._loader) + except: + raise AnsibleParserError("The tasks/main.yml file for role '%s' must contain a list of tasks" % self._role_name , obj=task_data) handler_data = self._load_role_yaml('handlers') if handler_data: - self._handler_blocks = load_list_of_blocks(handler_data, play=self._play, role=self, use_handlers=True, loader=self._loader) + try: + self._handler_blocks = load_list_of_blocks(handler_data, play=self._play, role=self, use_handlers=True, loader=self._loader) + except: + raise AnsibleParserError("The handlers/main.yml file for role '%s' must contain a list of tasks" % self._role_name , obj=task_data) # vars and default vars are regular dictionaries self._role_vars = self._load_role_yaml('vars')