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 00000000000..74457ae95d5 --- /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 9296e656d4c..4eb705ae2f5 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 ebe2273e896..7b769139c6b 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'