Skip to content

Commit 0d409d2

Browse files
committed
custom_logger: except AnsibleError and try to get more info on failing callback plugin
1 parent 90c1a3e commit 0d409d2

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

callback_plugins/custom_logger.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import os
55
import re
66

7+
8+
from ansible.errors import AnsibleCallbackError
9+
from ansible.errors import AnsibleError
710
from ansible.plugins.callback import CallbackBase
811

912
DOCUMENTATION = '''
@@ -63,18 +66,35 @@ def log_task_result(self, host, result, task_name):
6366
self.results[host][result] += 1
6467

6568
def log_summary_results(self, host):
69+
# The issue is presenting itself in this method
6670
file_path = os.path.join(self.output_dir, f"summary_results.log")
71+
# temperorily add more detail to the output
72+
print(self.results)
73+
6774
with open(file_path, 'w') as f:
6875
f.write(f"Host: {host}\n")
69-
f.write(f"Tasks Succeeded: {self.results[host]['passed']}\n")
70-
f.write(f"Tasks Failed: {self.results[host]['failed']}\n")
71-
f.write(f"Tasks Skipped: {self.results[host]['skipped']}\n")
72-
f.write("Failed Tasks:\n")
73-
for task_name in self.results[host]['failed_task_names']:
74-
f.write(f" - {task_name}\n")
75-
f.write("Succeeded Tasks:\n")
76-
for task_name in self.results[host]['ok_task_names']:
77-
f.write(f" - {task_name}\n")
76+
# This is the failed issue.
77+
# Why is it happening?
78+
# Unknown. But does it happen for the other values.
79+
# It is happening for compute-0
80+
# I need to see the partial log file, so this should NOT cause a failure.
81+
# try/catch ANY exception
82+
# It could be a nice upgrade to use jinja2 template to render this file.
83+
# IS the issue that there were 'f's preceeding the strings?
84+
try:
85+
f.write("Tasks Succeeded: {self.results[host]['passed']}\n")
86+
f.write("Tasks Failed: {self.results[host]['failed']}\n")
87+
f.write("Tasks Skipped: {self.results[host]['skipped']}\n")
88+
f.write("Failed Tasks:\n")
89+
for task_name in self.results[host]['failed_task_names']:
90+
f.write(f" - {task_name}\n")
91+
f.write("Succeeded Tasks:\n")
92+
for task_name in self.results[host]['ok_task_names']:
93+
f.write(f" - {task_name}\n")
94+
except AnsibleError as e:
95+
# this is probably an AnsibleCallbackError
96+
print("Ooops, there was an error")
97+
print(e)
7898

7999
def v2_runner_on_ok(self, result):
80100
host = result._host.get_name()
@@ -89,4 +109,4 @@ def v2_runner_on_failed(self, result, ignore_errors=False):
89109
def v2_runner_on_skipped(self, result):
90110
host = result._host.get_name()
91111
task_name = result._task.get_name()
92-
self.log_task_result(host, 'skipped', task_name)
112+
self.log_task_result(host, 'skipped', task_name)

0 commit comments

Comments
 (0)