From d6f26521eb62c82a74fbf9e56252211cff24d54a Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 4 Nov 2025 22:19:19 +0200 Subject: [PATCH] 22:19 --- .../sot-updater-upgradecmd.yml | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/files/ansible-playbooks/sot-updater-upgradecmd.yml b/files/ansible-playbooks/sot-updater-upgradecmd.yml index 36636a3..3270f96 100644 --- a/files/ansible-playbooks/sot-updater-upgradecmd.yml +++ b/files/ansible-playbooks/sot-updater-upgradecmd.yml @@ -1,3 +1,4 @@ +--- # sot-updater.yml — Read fw on Dev1 + Dev2, publish to NetBox via Rabbit (telemetry mode) - name: Read fw on Dev1 + Dev2, publish NetBox custom fields (full base, AIRPINGs, soft-fail telemetry) @@ -108,26 +109,36 @@ nb_small: "{{ nb_kv.get('small', '') }}" nb_ok_line: "{{ nb_ok_line }}" - # --- Extract upgrade_cmd using a localhost shell against HEREDOC with actual content --- + + # --- Extract upgrade_cmd using a localhost shell (consume stdout_lines, robust to garbling) --- - name: "NB preflight | Capture upgrade_cmd from stdout (shell)" when: nb_script.stat.exists delegate_to: localhost ansible.builtin.shell: | - awk -F'=' ' + set -e + # Feed nb_onedevice_update.py output (structured stdout_lines) to awk. + # 1) Prefer exact "NB: upgrade_cmd=" + # 2) Fallback to any "NB: ...cmd=" (covers typos like upde_cmd) + # Print first match and exit; otherwise print empty line. + cat <<'EOF' | awk -F'=' ' + BEGIN{found=0} /^[[:space:]]*NB:[[:space:]]*upgrade_cmd[[:space:]]*=/ { - sub(/^[^=]+=[[:space:]]*/,""); print; exit + sub(/^[[:space:]]*NB:[[:space:]]*upgrade_cmd[[:space:]]*=/,""); print; found=1; exit } /^[[:space:]]*NB:.*cmd[[:space:]]*=/ { - sub(/^[^=]+=[[:space:]]*/,""); print; exit + sub(/^[[:space:]]*NB:[[:space:]]*/,""); + sub(/^[^=]+=[[:space:]]*/,""); print; found=1; exit } - END{ print "" } - ' <<'LINES' -{{ (nb_preflight.stdout | default('') | regex_replace('\r','')) }} -LINES + END{ if (!found) print "" } + ' + EOF args: executable: /bin/bash register: up_cmd_sh changed_when: false + vars: + # Render the heredoc content as the structured lines; safer than raw joined stdout + EOF: "{{ (nb_preflight.stdout_lines | default([])) | join('\n') }}" - name: "NB preflight | Normalize + debug upgrade_cmd" when: nb_script.stat.exists @@ -136,10 +147,10 @@ LINES nb_upgrade_cmd_raw: "{{ (up_cmd_sh.stdout | default('')) | regex_replace('\r','') | trim }}" nb_upgrade_cmd: >- {{ - '' if ((up_cmd_sh.stdout | default('') | trim | lower) in ['none','null','']) + '' if ( (up_cmd_sh.stdout | default('') | trim) | lower ) in ['none','null',''] else (up_cmd_sh.stdout | default('') | trim) }} - nb_upgrade_cmd_len: "{{ ((up_cmd_sh.stdout | default('') | trim) | length) }}" + nb_upgrade_cmd_len: "{{ ( (up_cmd_sh.stdout | default('') | trim) | length ) }}" - name: "NB preflight | Debug upgrade_cmd" when: nb_script.stat.exists delegate_to: localhost @@ -148,6 +159,7 @@ LINES - "upgrade_cmd raw: '{{ nb_upgrade_cmd_raw }}'" - "upgrade_cmd parsed: '{{ nb_upgrade_cmd }}' (len={{ nb_upgrade_cmd_len }})" + # --- Detect "cloud vs NetBox (before update) was different" (regex-free, robust) - name: "NB preflight | Detect whether IP changed (pre-update)" when: nb_script.stat.exists