mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
straight up: ruff format (#11329)
* straight up: ruff format * Apply suggestions from code review
This commit is contained in:
@@ -11,20 +11,21 @@ from ansible.plugins.action import ActionBase
|
||||
try:
|
||||
from ansible.utils.datatag import trust_value as _trust_value
|
||||
except ImportError:
|
||||
|
||||
def _trust_value(input):
|
||||
return input
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
''' Fail with custom message '''
|
||||
"""Fail with custom message"""
|
||||
|
||||
_requires_connection = False
|
||||
|
||||
_VALID_ARGS = frozenset(('msg', 'that'))
|
||||
_VALID_ARGS = frozenset(("msg", "that"))
|
||||
|
||||
def _make_safe(self, text):
|
||||
# A simple str(text) won't do it since AnsibleUnsafeText is clever :-)
|
||||
return ''.join(chr(ord(x)) for x in text)
|
||||
return "".join(chr(ord(x)) for x in text)
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
if task_vars is None:
|
||||
@@ -33,18 +34,18 @@ class ActionModule(ActionBase):
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
if 'that' not in self._task.args:
|
||||
if "that" not in self._task.args:
|
||||
raise AnsibleError('conditional required in "that" string')
|
||||
|
||||
fail_msg = 'Assertion failed'
|
||||
success_msg = 'All assertions passed'
|
||||
fail_msg = "Assertion failed"
|
||||
success_msg = "All assertions passed"
|
||||
|
||||
thats = self._task.args['that']
|
||||
thats = self._task.args["that"]
|
||||
|
||||
result['_ansible_verbose_always'] = True
|
||||
result["_ansible_verbose_always"] = True
|
||||
|
||||
for that in thats:
|
||||
if hasattr(self._templar, 'evaluate_conditional'):
|
||||
if hasattr(self._templar, "evaluate_conditional"):
|
||||
trusted_that = _trust_value(that) if _trust_value else that
|
||||
test_result = self._templar.evaluate_conditional(conditional=trusted_that)
|
||||
else:
|
||||
@@ -52,14 +53,14 @@ class ActionModule(ActionBase):
|
||||
cond.when = [str(self._make_safe(that))]
|
||||
test_result = cond.evaluate_conditional(templar=self._templar, all_vars=task_vars)
|
||||
if not test_result:
|
||||
result['failed'] = True
|
||||
result['evaluated_to'] = test_result
|
||||
result['assertion'] = that
|
||||
result["failed"] = True
|
||||
result["evaluated_to"] = test_result
|
||||
result["assertion"] = that
|
||||
|
||||
result['msg'] = fail_msg
|
||||
result["msg"] = fail_msg
|
||||
|
||||
return result
|
||||
|
||||
result['changed'] = False
|
||||
result['msg'] = success_msg
|
||||
result["changed"] = False
|
||||
result["msg"] = success_msg
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user