From c5609c51bffb552d53aa91491430b46774a7f572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Wed, 20 Mar 2019 19:17:20 +0100 Subject: [PATCH] include_tasks: fix traceback if no file specified (#54044) --- .../54044-fix-include_task-no-file-traceback.yml | 2 ++ lib/ansible/playbook/task_include.py | 2 +- .../include_import/tasks/test_include_tasks.yml | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/54044-fix-include_task-no-file-traceback.yml diff --git a/changelogs/fragments/54044-fix-include_task-no-file-traceback.yml b/changelogs/fragments/54044-fix-include_task-no-file-traceback.yml new file mode 100644 index 0000000000..74457ae95d --- /dev/null +++ b/changelogs/fragments/54044-fix-include_task-no-file-traceback.yml @@ -0,0 +1,2 @@ +bugfixes: + - include_task - Fixed an unexpected exception if no file was given to include. diff --git a/lib/ansible/playbook/task_include.py b/lib/ansible/playbook/task_include.py index 9296e656d4..4eb705ae2f 100644 --- a/lib/ansible/playbook/task_include.py +++ b/lib/ansible/playbook/task_include.py @@ -69,7 +69,7 @@ class TaskInclude(Task): raise AnsibleParserError('Invalid options for %s: %s' % (task.action, ','.join(list(bad_opts))), obj=data) if not task.args.get('_raw_params'): - task.args['_raw_params'] = task.args.pop('file') + task.args['_raw_params'] = task.args.pop('file', None) apply_attrs = task.args.get('apply', {}) if apply_attrs and task.action != 'include_tasks': diff --git a/test/integration/targets/include_import/tasks/test_include_tasks.yml b/test/integration/targets/include_import/tasks/test_include_tasks.yml index ebe2273e89..7b769139c6 100644 --- a/test/integration/targets/include_import/tasks/test_include_tasks.yml +++ b/test/integration/targets/include_import/tasks/test_include_tasks.yml @@ -42,3 +42,13 @@ - name: include_tasks + action action: include_tasks tasks1.yml + + - name: test fail as expected without file + include_tasks: + ignore_errors: yes + register: res + + - name: verify fail as expected without file + assert: + that: + - res.msg == 'No include file was specified to the include'