This commit is contained in:
2025-11-04 16:16:39 +02:00
parent 89c282465e
commit 11d221e598

View File

@@ -79,13 +79,16 @@
- "{{ (nb_preflight.stderr_lines | default(['<no stderr>'])) }}"
- "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 <old-ip> 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