diff --git a/lso/playbook.py b/lso/playbook.py index 7855588ee971383ace99f639c9c45fc26cfd9c3b..4475f7d7e83f5ede5db4ee6dfbf20088779c81ae 100644 --- a/lso/playbook.py +++ b/lso/playbook.py @@ -7,6 +7,7 @@ import uuid import ansible_runner import requests +import xmltodict from pydantic import BaseModel, HttpUrl logger = logging.getLogger(__name__) @@ -89,6 +90,7 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent "invocation", "include", "include_args", + "server_capabilities", ] for line in json_content.strip().splitlines(): try: @@ -110,8 +112,18 @@ def _run_playbook_proc(job_id: str, playbook_path: str, extra_vars: dict, invent continue if "diff_lines" in task_result: + # Juniper-specific # Prevent the diff from being displayed twice, and only keep the formatted version. task_result.pop("diff", None) + elif "before" in task_result["diff"] and "after" in task_result["diff"]: + # Nokia-specific + # We have a chunk of Nokia config, and we would like to show the actual diff, not a full before and + # after. This will take some extra steps. + before_parsed = xmltodict.parse(task_result["diff"]["before"]) + after_parsed = xmltodict.parse(task_result["diff"]["after"]) + # Only leave the diff in the resulting output + task_result["diff"] = {k: v for k, v in after_parsed.items() if + k not in before_parsed or v != before_parsed[k]} if bool(task_result): # Only add the event if there are any relevant keys left.