mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Adding success_msg to assert (#41048)
* Adding success_msg to assert * Added missing version_added. Importing and checking string_types.
This commit is contained in:
parent
50e776877d
commit
0d885260a5
2 changed files with 14 additions and 2 deletions
|
@ -30,6 +30,10 @@ options:
|
||||||
msg:
|
msg:
|
||||||
description:
|
description:
|
||||||
- "The customized message used for a failing assertion"
|
- "The customized message used for a failing assertion"
|
||||||
|
success_msg:
|
||||||
|
version_added: "2.7"
|
||||||
|
description:
|
||||||
|
- "The customized message used for a successful assertion"
|
||||||
notes:
|
notes:
|
||||||
- This module is also supported for Windows targets.
|
- This module is also supported for Windows targets.
|
||||||
author:
|
author:
|
||||||
|
@ -50,4 +54,5 @@ EXAMPLES = '''
|
||||||
- "my_param <= 100"
|
- "my_param <= 100"
|
||||||
- "my_param >= 0"
|
- "my_param >= 0"
|
||||||
msg: "'my_param' must be between 0 and 100"
|
msg: "'my_param' must be between 0 and 100"
|
||||||
|
success_msg: "'my_param' is between 0 and 100"
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -20,6 +20,7 @@ __metaclass__ = type
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.playbook.conditional import Conditional
|
from ansible.playbook.conditional import Conditional
|
||||||
from ansible.plugins.action import ActionBase
|
from ansible.plugins.action import ActionBase
|
||||||
|
from ansible.module_utils.six import string_types
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(ActionBase):
|
class ActionModule(ActionBase):
|
||||||
|
@ -38,8 +39,11 @@ class ActionModule(ActionBase):
|
||||||
raise AnsibleError('conditional required in "that" string')
|
raise AnsibleError('conditional required in "that" string')
|
||||||
|
|
||||||
msg = None
|
msg = None
|
||||||
if 'msg' in self._task.args:
|
success_msg = None
|
||||||
|
if 'msg' in self._task.args and isinstance(self._task.args['msg'], string_types):
|
||||||
msg = self._task.args['msg']
|
msg = self._task.args['msg']
|
||||||
|
if 'success_msg' in self._task.args and isinstance(self._task.args['success_msg'], string_types):
|
||||||
|
success_msg = self._task.args['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']
|
||||||
|
@ -67,5 +71,8 @@ class ActionModule(ActionBase):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
result['changed'] = False
|
result['changed'] = False
|
||||||
result['msg'] = 'All assertions passed'
|
if success_msg is not None:
|
||||||
|
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