Show failed tasks in the final report.
This commit is contained in:
parent
ed06613f8e
commit
9eb5aabba4
|
@ -3,6 +3,7 @@ import asyncio
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from collections import defaultdict
|
||||||
from shutil import get_terminal_size
|
from shutil import get_terminal_size
|
||||||
from time import perf_counter
|
from time import perf_counter
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
@ -37,7 +38,7 @@ def prepare_chunk(playbook, chunk: str) -> Tuple[str, str, str]:
|
||||||
if "changed:" in lines[1]:
|
if "changed:" in lines[1]:
|
||||||
return ("CHANGED", playbook, chunk)
|
return ("CHANGED", playbook, chunk)
|
||||||
if "failed:" in lines[1] or "fatal:" in lines[1]:
|
if "failed:" in lines[1] or "fatal:" in lines[1]:
|
||||||
return ("FAILED", playbook, chunk)
|
return ("ERROR", playbook, chunk)
|
||||||
if "unreachable:" in lines[1]:
|
if "unreachable:" in lines[1]:
|
||||||
return ("UNREACHABLE", playbook, chunk)
|
return ("UNREACHABLE", playbook, chunk)
|
||||||
if chunk.startswith("TASK"):
|
if chunk.startswith("TASK"):
|
||||||
|
@ -96,7 +97,7 @@ def truncate(string, max_width):
|
||||||
|
|
||||||
|
|
||||||
async def show_progression(results: asyncio.Queue, playbooks: List[str], stream):
|
async def show_progression(results: asyncio.Queue, playbooks: List[str], stream):
|
||||||
recaps = {}
|
recaps = defaultdict(list)
|
||||||
starts = {}
|
starts = {}
|
||||||
ends = {}
|
ends = {}
|
||||||
currently_running = []
|
currently_running = []
|
||||||
|
@ -132,32 +133,31 @@ async def show_progression(results: asyncio.Queue, playbooks: List[str], stream)
|
||||||
stream.write("\033[m") # Select Graphic Rendition: Attributes off.
|
stream.write("\033[m") # Select Graphic Rendition: Attributes off.
|
||||||
stream.write(msg)
|
stream.write(msg)
|
||||||
if msgtype == "RECAP":
|
if msgtype == "RECAP":
|
||||||
recaps[playbook] = msg
|
recaps[playbook].append(msg)
|
||||||
if msgtype == "TASK":
|
if msgtype == "TASK":
|
||||||
stream.write("\033[0K") # EL – Erase In Line with parameter 0.
|
stream.write("\033[0K") # EL – Erase In Line with parameter 0.
|
||||||
stream.write("\033[m") # Select Graphic Rendition: Attributes off.
|
stream.write("\033[m") # Select Graphic Rendition: Attributes off.
|
||||||
stream.write(
|
stream.write(
|
||||||
truncate(msg.split("\n")[0], max_width=columns - longest_name - 4)
|
truncate(msg.split("\n")[0], max_width=columns - longest_name - 4)
|
||||||
)
|
)
|
||||||
if (
|
if msgtype == "ERROR":
|
||||||
msgtype == "ERROR"
|
recaps[playbook].append(msg)
|
||||||
): # Collect lines that start with "ERROR" for the recap
|
|
||||||
recaps[playbook] = (
|
|
||||||
"\n".join([line for line in msg.split("\n") if "ERROR" in line])
|
|
||||||
+ "\n"
|
|
||||||
)
|
|
||||||
stream.write(f"\033[{diff}B")
|
stream.write(f"\033[{diff}B")
|
||||||
stream.write(f"\033[{columns + 1}D")
|
stream.write(f"\033[{columns + 1}D")
|
||||||
stream.flush()
|
stream.flush()
|
||||||
finally:
|
finally:
|
||||||
stream.write(ENABLE_CURSOR)
|
stream.write(ENABLE_CURSOR)
|
||||||
stream.flush()
|
stream.flush()
|
||||||
|
|
||||||
|
stream.write("\n")
|
||||||
for playbook, recap in recaps.items():
|
for playbook, recap in recaps.items():
|
||||||
stream.write(
|
stream.write(
|
||||||
f"# Playbook {playbook}, ran in {ends[playbook] - starts[playbook]:.0f}s\n"
|
f"# Playbook {playbook}, ran in {ends[playbook] - starts[playbook]:.0f}s\n"
|
||||||
)
|
)
|
||||||
for line in recap.split("\n"):
|
for chunk in recap:
|
||||||
if "PLAY RECAP" not in line:
|
for line in chunk.split("\n"):
|
||||||
|
if "PLAY RECAP" in line:
|
||||||
|
continue
|
||||||
stream.write(line)
|
stream.write(line)
|
||||||
stream.write("\n")
|
stream.write("\n")
|
||||||
stream.flush()
|
stream.flush()
|
||||||
|
@ -179,9 +179,7 @@ async def amain():
|
||||||
*[
|
*[
|
||||||
run_playbook(playbook, remaining_args, results_queue)
|
run_playbook(playbook, remaining_args, results_queue)
|
||||||
for playbook in args.playbook
|
for playbook in args.playbook
|
||||||
],
|
])
|
||||||
return_exceptions=True,
|
|
||||||
)
|
|
||||||
await results_queue.put(None)
|
await results_queue.put(None)
|
||||||
await printer_task
|
await printer_task
|
||||||
return sum(results)
|
return sum(results)
|
||||||
|
|
|
@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
||||||
[project]
|
[project]
|
||||||
name = "ansible-parallel"
|
name = "ansible-parallel"
|
||||||
# Format is YYYY.MM.DD (https://calver.org/)
|
# Format is YYYY.MM.DD (https://calver.org/)
|
||||||
version = "2023.3.13"
|
version = "2023.7.26"
|
||||||
description = "Run ansible playbooks in parallel."
|
description = "Run ansible playbooks in parallel."
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Julien Palard", email = "julien@palard.fr" },
|
{ name = "Julien Palard", email = "julien@palard.fr" },
|
||||||
|
|
Loading…
Reference in New Issue