mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
Check type of fail_msg and success_msg
This commit is contained in:
parent
24189e7639
commit
0586cb1536
1 changed files with 13 additions and 12 deletions
|
@ -40,13 +40,18 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
fail_msg = None
|
fail_msg = None
|
||||||
success_msg = None
|
success_msg = None
|
||||||
if 'fail_msg' in self._task.args and isinstance(self._task.args['fail_msg'], string_types):
|
|
||||||
fail_msg = self._task.args['fail_msg']
|
|
||||||
elif 'msg' in self._task.args and isinstance(self._task.args['msg'], string_types):
|
|
||||||
fail_msg = self._task.args['msg']
|
|
||||||
|
|
||||||
if 'success_msg' in self._task.args and isinstance(self._task.args['success_msg'], string_types):
|
fail_msg = self._task.args.get('fail_msg', self._task.args.get('msg'))
|
||||||
success_msg = self._task.args['success_msg']
|
if fail_msg is None:
|
||||||
|
fail_msg = 'Assertion failed'
|
||||||
|
if not isinstance(fail_msg, string_types):
|
||||||
|
raise AnsibleError('Incorrect type for fail_msg or msg, expected string and got %s' % type(fail_msg))
|
||||||
|
|
||||||
|
success_msg = self._task.args.get('success_msg')
|
||||||
|
if success_msg is None:
|
||||||
|
success_msg = 'All assertions passed'
|
||||||
|
if not isinstance(success_msg, string_types):
|
||||||
|
raise AnsibleError('Incorrect type for success_msg, expected string and got %s' % type(success_msg))
|
||||||
|
|
||||||
# make sure the 'that' items are a list
|
# make sure the 'that' items are a list
|
||||||
thats = self._task.args['that']
|
thats = self._task.args['that']
|
||||||
|
@ -68,14 +73,10 @@ class ActionModule(ActionBase):
|
||||||
result['evaluated_to'] = test_result
|
result['evaluated_to'] = test_result
|
||||||
result['assertion'] = that
|
result['assertion'] = that
|
||||||
|
|
||||||
if fail_msg:
|
|
||||||
result['msg'] = fail_msg
|
result['msg'] = fail_msg
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
result['changed'] = False
|
result['changed'] = False
|
||||||
if success_msg is not None:
|
|
||||||
result['msg'] = success_msg
|
result['msg'] = success_msg
|
||||||
else:
|
|
||||||
result['msg'] = 'All assertions passed'
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue