From ce54a59cdc458add21cfee3750e21f21b25ad6fb Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 2 Dec 2015 10:35:20 -0600 Subject: [PATCH] Catch additional assertion errors for load_list_of_blocks --- lib/ansible/playbook/helpers.py | 5 +---- lib/ansible/playbook/role/__init__.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index 4b29e8b74f8..c4f11c1c8ed 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 9d65639785b..3cb914689fe 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')