[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:
patchback[bot] 2024-12-24 14:45:32 +01:00 committed by GitHub
parent a13a6d284c
commit 3c7f05c42d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 251 additions and 253 deletions

View file

@ -57,7 +57,10 @@ class CallbackModule(CallbackBase):
CALLBACK_NEEDS_WHITELIST = True
TIME_FORMAT = "%b %d %Y %H:%M:%S"
MSG_FORMAT = "%(now)s - %(playbook)s - %(task_name)s - %(task_action)s - %(category)s - %(data)s\n\n"
@staticmethod
def _make_msg(now, playbook, task_name, task_action, category, data):
return f"{now} - {playbook} - {task_name} - {task_action} - {category} - {data}\n\n"
def __init__(self):
@ -82,22 +85,12 @@ class CallbackModule(CallbackBase):
invocation = data.pop('invocation', None)
data = json.dumps(data, cls=AnsibleJSONEncoder)
if invocation is not None:
data = json.dumps(invocation) + " => %s " % data
data = f"{json.dumps(invocation)} => {data} "
path = os.path.join(self.log_folder, result._host.get_name())
now = time.strftime(self.TIME_FORMAT, time.localtime())
msg = to_bytes(
self.MSG_FORMAT
% dict(
now=now,
playbook=self.playbook,
task_name=result._task.name,
task_action=result._task.action,
category=category,
data=data,
)
)
msg = to_bytes(self._make_msg(now, self.playbook, result._task.name, result._task.action, category, data))
with open(path, "ab") as fd:
fd.write(msg)