Check if task file is specified for import_tasks (#57572)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-12-24 10:26:32 +05:30 committed by GitHub
parent 34acabd70a
commit 683c467609
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 10 deletions

View 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).

View file

@ -70,6 +70,8 @@ class TaskInclude(Task):
if not task.args.get('_raw_params'): if not task.args.get('_raw_params'):
task.args['_raw_params'] = task.args.pop('file', None) 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', {}) apply_attrs = task.args.get('apply', {})
if apply_attrs and task.action != 'include_tasks': if apply_attrs and task.action != 'include_tasks':

View file

@ -42,13 +42,3 @@
- name: include_tasks + action - name: include_tasks + action
action: include_tasks tasks1.yml 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'

View file

@ -31,6 +31,7 @@ from ansible.playbook.task_include import TaskInclude
from ansible.executor import task_result from ansible.executor import task_result
from ansible.playbook.included_file import IncludedFile from ansible.playbook.included_file import IncludedFile
from ansible.errors import AnsibleParserError
@pytest.fixture @pytest.fixture
@ -167,3 +168,24 @@ def test_process_include_simulate_free(mock_iterator, mock_variable_manager):
assert res[0]._vars == {} assert res[0]._vars == {}
assert res[1]._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)