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
|
||||
|
||||
@@ -37,17 +37,19 @@ def main():
|
||||
info = None
|
||||
|
||||
arg_formats = {}
|
||||
for arg, fmt_spec in p['arg_formats'].items():
|
||||
func = getattr(fmt, fmt_spec['func'])
|
||||
for arg, fmt_spec in p["arg_formats"].items():
|
||||
func = getattr(fmt, fmt_spec["func"])
|
||||
args = fmt_spec.get("args", [])
|
||||
|
||||
arg_formats[arg] = func(*args)
|
||||
|
||||
try:
|
||||
runner = CmdRunner(module, [module.params["cmd"], '--'], arg_formats=arg_formats, path_prefix=module.params["path_prefix"])
|
||||
runner = CmdRunner(
|
||||
module, [module.params["cmd"], "--"], arg_formats=arg_formats, path_prefix=module.params["path_prefix"]
|
||||
)
|
||||
|
||||
with runner.context(p['arg_order'], check_mode_skip=p['check_mode_skip']) as ctx:
|
||||
result = ctx.run(**p['arg_values'])
|
||||
with runner.context(p["arg_order"], check_mode_skip=p["check_mode_skip"]) as ctx:
|
||||
result = ctx.run(**p["arg_values"])
|
||||
info = ctx.run_info
|
||||
check = "check"
|
||||
rc, out, err = result if result is not None else (None, None, None)
|
||||
@@ -57,5 +59,5 @@ def main():
|
||||
module.fail_json(rc=1, module_stderr=traceback.format_exc(), msg="Module crashed with exception")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user