diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index e8df62f..ecb0fa4 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -79,13 +79,16 @@ - "{{ (nb_preflight.stderr_lines | default([''])) }}" - "raw stdout (joined): {{ nb_preflight.stdout | default('') | trim }}" - # --- Parse the OK line for reuse (device/ip/fw/etc.) --- - - name: "NB preflight | Parse OK line" + + # --- Parse the OK line robustly (line-by-line) --- + - name: "NB preflight | Parse OK line (robust)" when: nb_script.stat.exists delegate_to: localhost vars: + nb_lines: >- + {{ (nb_preflight.stdout | default('') | regex_replace('\r','')) | split('\n') | map('trim') | list }} nb_ok_line: >- - {{ (nb_preflight.stdout | default('') | regex_findall('^OK\\s+.*$', multiline=True)) | last | default('') }} + {{ (nb_lines | select('match', '^OK\\s+') | list | last | default('')) }} nb_groups: >- {{ (nb_ok_line | regex_findall('^OK\\s+(\\S+)\\s+ip=([^\\s]+)\\s+fw=([^\\s]+)\\s+node=([^\\s]+)\\s+sector=([^\\s]+)\\s+small=([^\\s]+)')) | first | default([]) }} set_fact: @@ -98,13 +101,16 @@ nb_small: "{{ nb_groups[5] | default('') }}" nb_ok_line: "{{ nb_ok_line }}" - # --- Heuristic for "cloud IP different from NetBox before update" --- - # We detect this via the script's chatty line: "IP: moving from iface=... -> ..." + # --- Detect "was different before update" via the script's own signal line --- - name: "NB preflight | Detect whether IP changed (cloud vs prior NetBox)" when: nb_script.stat.exists delegate_to: localhost + vars: + nb_lines: >- + {{ (nb_preflight.stdout | default('') | regex_replace('\r','')) | split('\n') | map('trim') | list }} set_fact: - nb_ip_changed: "{{ (nb_preflight.stdout | default('')) is search('^IP:\\s+moving\\s+[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\s+from\\s+iface=', multiline=True) }}" + nb_ip_changed: "{{ (nb_lines | select('match', '^IP:\\s+moving\\s+[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\s+from\\s+iface=') | list | length) > 0 }}" + - name: "NB preflight | Verdict" when: nb_script.stat.exists