From 41ef09988b652ffbb1bbcddabccbc0e25c834c73 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Thu, 7 Sep 2023 15:32:48 +0200 Subject: [PATCH] Parse running config adequately. --- partition/roles/sonic/tasks/main.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/partition/roles/sonic/tasks/main.yaml b/partition/roles/sonic/tasks/main.yaml index 50756af76..59c0372aa 100644 --- a/partition/roles/sonic/tasks/main.yaml +++ b/partition/roles/sonic/tasks/main.yaml @@ -55,13 +55,17 @@ when: sonic_breakouts is defined - name: Delete deprecated metal.yaml - file: + ansible.builtin.file: path: "/etc/sonic/metal.yaml" state: absent - name: Get running configuration ansible.builtin.command: show runningconfiguration all - register: sonic_running_cfg + register: sonic_running_cfg_result + +- name: Parse running configuration + ansible.builtin.set_fact: + sonic_running_cfg: "{{ sonic_running_cfg_result.stdout | from_json }}" - name: Extract running configuration for breakouts and ports ansible.builtin.set_fact: @@ -74,11 +78,11 @@ - name: Fail if running configuration doesn't contain required information ansible.builtin.assert: that: - - sonic_running_cfg_breakouts is defined and sonic_running_cfg_breakouts | length > 0 - - sonic_running_cfg_hwsku is defined and sonic_running_cfg_hwsku | length > 0 - - sonic_running_cfg_mac is defined and sonic_running_cfg_mac | length > 0 - - sonic_running_cfg_platform is defined and sonic_running_cfg_platform | length > 0 - - sonic_running_cfg_ports is defined and sonic_running_cfg_ports | length > 0 + - sonic_running_cfg_breakouts + - sonic_running_cfg_hwsku + - sonic_running_cfg_mac + - sonic_running_cfg_platform + - sonic_running_cfg_ports fail_msg: The running configuration is incomplete because it does not contain 'BREAKOUT_CFG', 'PORT', or complete 'DEVICE_METADATA'. - name: Fail if running configuration doesn't contain 'PORT' @@ -93,7 +97,7 @@ - name: Save config_db as JSON file copy: content: "{{ config_db | from_yaml | to_nice_json }}" - dest: /etc/sonic/config_db.json + dest: /etc/sonic/config_db.bak.json diff: true # notify: "config {{ sonic_config_action }}"