Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to prettify xml with netconf_config before making diff #645

Open
33Fraise33 opened this issue Jun 7, 2024 · 1 comment
Open
Assignees

Comments

@33Fraise33
Copy link

33Fraise33 commented Jun 7, 2024

SUMMARY

We have a vendor where the xml is minified to a 1 line xml. If we run netconf_config with --diff we are getting the full configuration before and after as the config is only one line and there is a change on that line.
It would come in handy to pass an option to the module to prettify the xml before taking the diff. This way we can actually have meaningful use of --diff --check

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ansible.netcommon.netconf_config

ADDITIONAL INFORMATION

see summary

- name: Nc-cli change netconf server config
  ansible.netcommon.netconf_config:
    content: "{{ lookup('template', 'config_swind_vrf_netconf_server.xml.j2') }}"
@33Fraise33
Copy link
Author

33Fraise33 commented Jun 10, 2024

I was able to implement a workaround with an include_role that has this content, even though it is not perfect:

- name: 6WIND - {{ swind_play_name }}
  ansible.netcommon.netconf_config:
    content: "{{ swind_template_content }}"
  no_log: true  # needed to prevent diff output from module, do nut use diff: false as it will not register output
  register: swind_netconf_output
- name: 6WIND - Set diff facts
  ansible.builtin.set_fact:
    netconf_before: "{{ swind_netconf_output.diff.before | ansible.utils.from_xml }}"
    netconf_after: "{{ swind_netconf_output.diff.after | ansible.utils.from_xml }}"
  when: swind_netconf_output.diff is defined
- name: 6WIND - Show diff
  ansible.utils.fact_diff:
    before: "{{ netconf_before | ansible.utils.to_paths }}"
    after: "{{ netconf_after | ansible.utils.to_paths }}"
  when: swind_netconf_output.diff is defined

This results in:

--- before
+++ after
@@ -465,7 +465,7 @@
     "data.config.vrf[2].interface.physical[0].ipv6.enabled": "false",
     "data.config.vrf[2].interface.physical[0].name": "ens2f0",
     "data.config.vrf[2].interface.physical[0].port": "pci-b0s6",
-    "data.config.vrf[2].interface.physical[1].description": "SW02",
+    "data.config.vrf[2].interface.physical[1].description": "SW02-CHANGED",
     "data.config.vrf[2].interface.physical[1].enabled": "true",
     "data.config.vrf[2].interface.physical[1].ipv4.enabled": "false",
     "data.config.vrf[2].interface.physical[1].ipv6.enabled": "false",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants