Compare commits
2
Commits
main
..
84765aa6e9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84765aa6e9 | ||
|
|
d1fbe94d3f |
@@ -1,59 +1,23 @@
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
def parse_file(file_path):
|
def parse_file(file_path):
|
||||||
recap_results = []
|
results = []
|
||||||
failed_tasks = defaultdict(list)
|
|
||||||
|
|
||||||
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||||
lines = f.readlines()
|
for line in f:
|
||||||
|
|
||||||
current_task = None
|
# Look for lines containing recap info
|
||||||
|
|
||||||
for i, line in enumerate(lines):
|
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
# 1. Detect TASK name
|
|
||||||
# -------------------------
|
|
||||||
task_match = re.search(r"TASK \[(.*?)\]", line)
|
|
||||||
if task_match:
|
|
||||||
current_task = task_match.group(1)
|
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
# 2. Detect FAILED lines
|
|
||||||
# -------------------------
|
|
||||||
fail_match = re.search(r"fatal: \[(.*?)\]: FAILED!", line)
|
|
||||||
if fail_match:
|
|
||||||
host = fail_match.group(1)
|
|
||||||
|
|
||||||
# Try to grab error message from same or next lines
|
|
||||||
error_msg = ""
|
|
||||||
|
|
||||||
# Look ahead a few lines to capture reason
|
|
||||||
for j in range(i, min(i + 5, len(lines))):
|
|
||||||
if "msg" in lines[j] or "stderr" in lines[j]:
|
|
||||||
error_msg += lines[j].strip() + " "
|
|
||||||
|
|
||||||
if not error_msg:
|
|
||||||
error_msg = "Unknown error"
|
|
||||||
|
|
||||||
failed_tasks[host].append({
|
|
||||||
"task": current_task,
|
|
||||||
"error": error_msg.strip()
|
|
||||||
})
|
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
# 3. Parse PLAY RECAP lines
|
|
||||||
# -------------------------
|
|
||||||
if "ok=" in line and "failed=" in line and "unreachable=" in line:
|
if "ok=" in line and "failed=" in line and "unreachable=" in line:
|
||||||
|
|
||||||
|
# Extract host (first non-time token before :)
|
||||||
host_match = re.search(r"(?:\d{2}:\d{2}:\d{2}\s+)?(\S+)\s+:", line)
|
host_match = re.search(r"(?:\d{2}:\d{2}:\d{2}\s+)?(\S+)\s+:", line)
|
||||||
if not host_match:
|
if not host_match:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
host = host_match.group(1)
|
host = host_match.group(1)
|
||||||
|
|
||||||
|
# Extract values individually (order-independent)
|
||||||
def get_value(field):
|
def get_value(field):
|
||||||
match = re.search(rf"{field}=(\d+)", line)
|
match = re.search(rf"{field}=(\d+)", line)
|
||||||
return int(match.group(1)) if match else 0
|
return int(match.group(1)) if match else 0
|
||||||
@@ -69,7 +33,7 @@ def parse_file(file_path):
|
|||||||
else "OK"
|
else "OK"
|
||||||
)
|
)
|
||||||
|
|
||||||
recap_results.append({
|
results.append({
|
||||||
"host": host,
|
"host": host,
|
||||||
"ok": ok,
|
"ok": ok,
|
||||||
"changed": changed,
|
"changed": changed,
|
||||||
@@ -78,10 +42,10 @@ def parse_file(file_path):
|
|||||||
"status": status
|
"status": status
|
||||||
})
|
})
|
||||||
|
|
||||||
return recap_results, failed_tasks
|
return results
|
||||||
|
|
||||||
|
|
||||||
def print_report(results, failed_tasks):
|
def print_report(results):
|
||||||
unreachable_hosts = []
|
unreachable_hosts = []
|
||||||
failed_hosts = []
|
failed_hosts = []
|
||||||
|
|
||||||
@@ -104,22 +68,7 @@ def print_report(results, failed_tasks):
|
|||||||
print("\nFAILED HOSTS:")
|
print("\nFAILED HOSTS:")
|
||||||
print("\n".join(failed_hosts) if failed_hosts else " None")
|
print("\n".join(failed_hosts) if failed_hosts else " None")
|
||||||
|
|
||||||
# -------------------------
|
|
||||||
# NEW SECTION
|
|
||||||
# -------------------------
|
|
||||||
print("\n=== FAILED TASK DETAILS ===")
|
|
||||||
|
|
||||||
if not failed_tasks:
|
|
||||||
print(" No failed tasks detected")
|
|
||||||
return
|
|
||||||
|
|
||||||
for host, tasks in failed_tasks.items():
|
|
||||||
print(f"\n{host}")
|
|
||||||
for t in tasks:
|
|
||||||
print(f" Task: {t['task']}")
|
|
||||||
print(f" Error: {t['error']}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
results, failed_tasks = parse_file(sys.argv[1])
|
results = parse_file(sys.argv[1])
|
||||||
print_report(results, failed_tasks)
|
print_report(results)
|
||||||
|
|||||||
Reference in New Issue
Block a user