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..a596184fe4 --- /dev/null +++ b/changelogs/fragments/54044-fix-include_task-no-file-traceback.yml @@ -0,0 +1,2 @@ +bugfixes: + - include_tasks - 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 ba048311a1..40c3aefe84 100644 --- a/lib/ansible/playbook/task_include.py +++ b/lib/ansible/playbook/task_include.py @@ -67,7 +67,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'