mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
[PR #9321/c3ed2144 backport][stable-10] callback plugins: use f-strings (#9357)
callback plugins: use f-strings (#9321)
* callback plugins: use f-strings
* add changelog frag
* manual change for few occurrences
* manual change for few occurrences
* adjustment from review
* adjustment from review
* adjustment from review
* Update plugins/callback/splunk.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* replace str templating with JSON templating
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c3ed2144e2
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
a13a6d284c
commit
3c7f05c42d
22 changed files with 251 additions and 253 deletions
|
@ -71,7 +71,7 @@ class CallbackModule(CallbackBase):
|
|||
if not name:
|
||||
msg = u"play"
|
||||
else:
|
||||
msg = u"PLAY [%s]" % name
|
||||
msg = f"PLAY [{name}]"
|
||||
|
||||
self._play = play
|
||||
|
||||
|
@ -91,25 +91,17 @@ class CallbackModule(CallbackBase):
|
|||
for host in hosts:
|
||||
stat = stats.summarize(host)
|
||||
|
||||
self._display.display(u"%s : %s %s %s %s %s %s" % (
|
||||
hostcolor(host, stat),
|
||||
colorize(u'ok', stat['ok'], C.COLOR_OK),
|
||||
colorize(u'changed', stat['changed'], C.COLOR_CHANGED),
|
||||
colorize(u'unreachable', stat['unreachable'], C.COLOR_UNREACHABLE),
|
||||
colorize(u'failed', stat['failures'], C.COLOR_ERROR),
|
||||
colorize(u'rescued', stat['rescued'], C.COLOR_OK),
|
||||
colorize(u'ignored', stat['ignored'], C.COLOR_WARN)),
|
||||
self._display.display(
|
||||
f"{hostcolor(host, stat)} : {colorize(u'ok', stat['ok'], C.COLOR_OK)} {colorize(u'changed', stat['changed'], C.COLOR_CHANGED)} "
|
||||
f"{colorize(u'unreachable', stat['unreachable'], C.COLOR_UNREACHABLE)} {colorize(u'failed', stat['failures'], C.COLOR_ERROR)} "
|
||||
f"{colorize(u'rescued', stat['rescued'], C.COLOR_OK)} {colorize(u'ignored', stat['ignored'], C.COLOR_WARN)}",
|
||||
screen_only=True
|
||||
)
|
||||
|
||||
self._display.display(u"%s : %s %s %s %s %s %s" % (
|
||||
hostcolor(host, stat, False),
|
||||
colorize(u'ok', stat['ok'], None),
|
||||
colorize(u'changed', stat['changed'], None),
|
||||
colorize(u'unreachable', stat['unreachable'], None),
|
||||
colorize(u'failed', stat['failures'], None),
|
||||
colorize(u'rescued', stat['rescued'], None),
|
||||
colorize(u'ignored', stat['ignored'], None)),
|
||||
self._display.display(
|
||||
f"{hostcolor(host, stat, False)} : {colorize(u'ok', stat['ok'], None)} {colorize(u'changed', stat['changed'], None)} "
|
||||
f"{colorize(u'unreachable', stat['unreachable'], None)} {colorize(u'failed', stat['failures'], None)} "
|
||||
f"{colorize(u'rescued', stat['rescued'], None)} {colorize(u'ignored', stat['ignored'], None)}",
|
||||
log_only=True
|
||||
)
|
||||
|
||||
|
@ -124,12 +116,14 @@ class CallbackModule(CallbackBase):
|
|||
for k in sorted(stats.custom.keys()):
|
||||
if k == '_run':
|
||||
continue
|
||||
self._display.display('\t%s: %s' % (k, self._dump_results(stats.custom[k], indent=1).replace('\n', '')))
|
||||
_custom_stats = self._dump_results(stats.custom[k], indent=1).replace('\n', '')
|
||||
self._display.display(f'\t{k}: {_custom_stats}')
|
||||
|
||||
# print per run custom stats
|
||||
if '_run' in stats.custom:
|
||||
self._display.display("", screen_only=True)
|
||||
self._display.display('\tRUN: %s' % self._dump_results(stats.custom['_run'], indent=1).replace('\n', ''))
|
||||
_custom_stats_run = self._dump_results(stats.custom['_run'], indent=1).replace('\n', '')
|
||||
self._display.display(f'\tRUN: {_custom_stats_run}')
|
||||
self._display.display("", screen_only=True)
|
||||
|
||||
def v2_playbook_on_task_start(self, task, is_conditional):
|
||||
|
@ -143,13 +137,13 @@ class CallbackModule(CallbackBase):
|
|||
# that they can secure this if they feel that their stdout is insecure
|
||||
# (shoulder surfing, logging stdout straight to a file, etc).
|
||||
if not task.no_log and C.DISPLAY_ARGS_TO_STDOUT:
|
||||
args = ', '.join(('%s=%s' % a for a in task.args.items()))
|
||||
args = ' %s' % args
|
||||
self._display.banner("TASK %d/%d [%s%s]" % (self._task_counter, self._task_total, task.get_name().strip(), args))
|
||||
args = ', '.join(('{k}={v}' for k, v in task.args.items()))
|
||||
args = f' {args}'
|
||||
self._display.banner(f"TASK {self._task_counter}/{self._task_total} [{task.get_name().strip()}{args}]")
|
||||
if self._display.verbosity >= 2:
|
||||
path = task.get_path()
|
||||
if path:
|
||||
self._display.display("task path: %s" % path, color=C.COLOR_DEBUG)
|
||||
self._display.display(f"task path: {path}", color=C.COLOR_DEBUG)
|
||||
self._host_counter = self._previous_batch_total
|
||||
self._task_counter += 1
|
||||
|
||||
|
@ -166,15 +160,15 @@ class CallbackModule(CallbackBase):
|
|||
return
|
||||
elif result._result.get('changed', False):
|
||||
if delegated_vars:
|
||||
msg = "changed: %d/%d [%s -> %s]" % (self._host_counter, self._host_total, result._host.get_name(), delegated_vars['ansible_host'])
|
||||
msg = f"changed: {self._host_counter}/{self._host_total} [{result._host.get_name()} -> {delegated_vars['ansible_host']}]"
|
||||
else:
|
||||
msg = "changed: %d/%d [%s]" % (self._host_counter, self._host_total, result._host.get_name())
|
||||
msg = f"changed: {self._host_counter}/{self._host_total} [{result._host.get_name()}]"
|
||||
color = C.COLOR_CHANGED
|
||||
else:
|
||||
if delegated_vars:
|
||||
msg = "ok: %d/%d [%s -> %s]" % (self._host_counter, self._host_total, result._host.get_name(), delegated_vars['ansible_host'])
|
||||
msg = f"ok: {self._host_counter}/{self._host_total} [{result._host.get_name()} -> {delegated_vars['ansible_host']}]"
|
||||
else:
|
||||
msg = "ok: %d/%d [%s]" % (self._host_counter, self._host_total, result._host.get_name())
|
||||
msg = f"ok: {self._host_counter}/{self._host_total} [{result._host.get_name()}]"
|
||||
color = C.COLOR_OK
|
||||
|
||||
self._handle_warnings(result._result)
|
||||
|
@ -185,7 +179,7 @@ class CallbackModule(CallbackBase):
|
|||
self._clean_results(result._result, result._task.action)
|
||||
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % (self._dump_results(result._result),)
|
||||
msg += f" => {self._dump_results(result._result)}"
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||
|
@ -206,14 +200,16 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
else:
|
||||
if delegated_vars:
|
||||
self._display.display("fatal: %d/%d [%s -> %s]: FAILED! => %s" % (self._host_counter, self._host_total,
|
||||
result._host.get_name(), delegated_vars['ansible_host'],
|
||||
self._dump_results(result._result)),
|
||||
color=C.COLOR_ERROR)
|
||||
self._display.display(
|
||||
f"fatal: {self._host_counter}/{self._host_total} [{result._host.get_name()} -> "
|
||||
f"{delegated_vars['ansible_host']}]: FAILED! => {self._dump_results(result._result)}",
|
||||
color=C.COLOR_ERROR
|
||||
)
|
||||
else:
|
||||
self._display.display("fatal: %d/%d [%s]: FAILED! => %s" % (self._host_counter, self._host_total,
|
||||
result._host.get_name(), self._dump_results(result._result)),
|
||||
color=C.COLOR_ERROR)
|
||||
self._display.display(
|
||||
f"fatal: {self._host_counter}/{self._host_total} [{result._host.get_name()}]: FAILED! => {self._dump_results(result._result)}",
|
||||
color=C.COLOR_ERROR
|
||||
)
|
||||
|
||||
if ignore_errors:
|
||||
self._display.display("...ignoring", color=C.COLOR_SKIP)
|
||||
|
@ -231,9 +227,9 @@ class CallbackModule(CallbackBase):
|
|||
if result._task.loop and 'results' in result._result:
|
||||
self._process_items(result)
|
||||
else:
|
||||
msg = "skipping: %d/%d [%s]" % (self._host_counter, self._host_total, result._host.get_name())
|
||||
msg = f"skipping: {self._host_counter}/{self._host_total} [{result._host.get_name()}]"
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
msg += f" => {self._dump_results(result._result)}"
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
|
@ -244,11 +240,13 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
delegated_vars = result._result.get('_ansible_delegated_vars', None)
|
||||
if delegated_vars:
|
||||
self._display.display("fatal: %d/%d [%s -> %s]: UNREACHABLE! => %s" % (self._host_counter, self._host_total,
|
||||
result._host.get_name(), delegated_vars['ansible_host'],
|
||||
self._dump_results(result._result)),
|
||||
color=C.COLOR_UNREACHABLE)
|
||||
self._display.display(
|
||||
f"fatal: {self._host_counter}/{self._host_total} [{result._host.get_name()} -> "
|
||||
f"{delegated_vars['ansible_host']}]: UNREACHABLE! => {self._dump_results(result._result)}",
|
||||
color=C.COLOR_UNREACHABLE
|
||||
)
|
||||
else:
|
||||
self._display.display("fatal: %d/%d [%s]: UNREACHABLE! => %s" % (self._host_counter, self._host_total,
|
||||
result._host.get_name(), self._dump_results(result._result)),
|
||||
color=C.COLOR_UNREACHABLE)
|
||||
self._display.display(
|
||||
f"fatal: {self._host_counter}/{self._host_total} [{result._host.get_name()}]: UNREACHABLE! => {self._dump_results(result._result)}",
|
||||
color=C.COLOR_UNREACHABLE
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue