Check if task file is specified for import_tasks (#57572)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
34acabd70a
commit
683c467609
4 changed files with 26 additions and 10 deletions
2
changelogs/fragments/54095-import_tasks-fix_no_task.yml
Normal file
2
changelogs/fragments/54095-import_tasks-fix_no_task.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- Raise error when no task file is provided to import_tasks (https://github.com/ansible/ansible/issues/54095).
|
|
@ -70,6 +70,8 @@ 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)
|
||||
|
||||
apply_attrs = task.args.get('apply', {})
|
||||
if apply_attrs and task.action != 'include_tasks':
|
||||
|
|
|
@ -42,13 +42,3 @@
|
|||
|
||||
- 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'
|
||||
|
|
|
@ -31,6 +31,7 @@ from ansible.playbook.task_include import TaskInclude
|
|||
from ansible.executor import task_result
|
||||
|
||||
from ansible.playbook.included_file import IncludedFile
|
||||
from ansible.errors import AnsibleParserError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -167,3 +168,24 @@ def test_process_include_simulate_free(mock_iterator, mock_variable_manager):
|
|||
|
||||
assert res[0]._vars == {}
|
||||
assert res[1]._vars == {}
|
||||
|
||||
|
||||
def test_empty_raw_params():
|
||||
parent_task_ds = {'debug': 'msg=foo'}
|
||||
parent_task = Task.load(parent_task_ds)
|
||||
parent_task._play = None
|
||||
|
||||
task_ds_list = [
|
||||
{
|
||||
'include': ''
|
||||
},
|
||||
{
|
||||
'include_tasks': ''
|
||||
},
|
||||
{
|
||||
'import_tasks': ''
|
||||
}
|
||||
]
|
||||
for task_ds in task_ds_list:
|
||||
with pytest.raises(AnsibleParserError):
|
||||
TaskInclude.load(task_ds, task_include=parent_task)
|
||||
|
|
Loading…
Reference in a new issue