Add location on include_tasks fail inside include (#83876)

Adds the datastore details to the parser error when attempting to
include tasks that contain include_tasks without a filename set. This
change will now display the exact location of the include_tasks that
failed like any normal syntax error.
pull/83760/head
Jordan Borean 3 months ago committed by GitHub
parent 4346430003
commit 1503805b70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,4 @@
bugfixes:
- >-
include_tasks - Display location when attempting to load a task list where ``include_*`` did not specify any value -
https://github.com/ansible/ansible/issues/83874

@ -74,7 +74,7 @@ class TaskInclude(Task):
if not task.args.get('_raw_params'):
task.args['_raw_params'] = task.args.pop('file', None)
if not task.args['_raw_params']:
raise AnsibleParserError('No file specified for %s' % task.action)
raise AnsibleParserError('No file specified for %s' % task.action, obj=data)
apply_attrs = task.args.get('apply', {})
if apply_attrs and task.action not in C._ACTION_INCLUDE_TASKS:

@ -0,0 +1,5 @@
- name: ping task
ansible.builtin.ping:
- name: invalid include_task definition
ansible.builtin.include_tasks:

@ -148,3 +148,9 @@ test "$(grep out.txt -ce 'In imported role')" = 3
# https://github.com/ansible/ansible/issues/73657
ansible-playbook issue73657.yml 2>&1 | tee issue73657.out
test "$(grep -c 'SHOULD_NOT_EXECUTE' issue73657.out)" = 0
# https://github.com/ansible/ansible/issues/83874
ansible-playbook test_null_include_filename.yml 2>&1 | tee test_null_include_filename.out
test "$(grep -c 'ERROR! No file specified for ansible.builtin.include_tasks' test_null_include_filename.out)" = 1
test "$(grep -c 'The error appears to be in '\''.*/include_import/null_filename/tasks.yml'\'': line 4, column 3.*' test_null_include_filename.out)" = 1
test "$(grep -c '\- name: invalid include_task definition' test_null_include_filename.out)" = 1

@ -0,0 +1,7 @@
- name: Test include failure with invalid included include_task
hosts: localhost
gather_facts: false
tasks:
- ansible.builtin.include_tasks:
file: null_filename/tasks.yml
Loading…
Cancel
Save