This commit is contained in:
2025-11-04 16:34:28 +02:00
parent 027ca612f5
commit afd365ffb0

View File

@@ -110,19 +110,21 @@
nb_small: "{{ nb_kv.get('small', '') }}"
nb_ok_line: "{{ nb_ok_line }}"
# --- Detect "cloud vs NetBox (before update) was different"
# Trigger on any of these lines from the Python script:
# "IP: moving ...", "IP: create new ...", "IP: pruning stale ..."
# --- 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
delegate_to: localhost
vars:
out: "{{ (nb_preflight.stdout | default('') | regex_replace('\r','')) }}"
change_lines: >-
{{ out | regex_findall('(?:^|\\n)(IP: (?:moving|create new|pruning stale)[^\\n]*)', multiline=True) }}
reason: >-
{%- if 'IP: moving ' in out -%}moving
{%- elif 'IP: create new ' in out -%}create new
{%- elif 'IP: pruning stale ' in out -%}pruning stale
{%- else -%}none{%- endif -%}
set_fact:
nb_ip_changed: "{{ (change_lines | length) > 0 }}"
nb_change_lines: "{{ change_lines }}"
nb_ip_changed: "{{ reason != 'none' }}"
nb_change_reason: "{{ reason }}"
- name: "NB preflight | Verdict"
when: nb_script.stat.exists
@@ -130,9 +132,10 @@
ansible.builtin.debug:
msg:
- "NB preflight verdict: {{ 'IP CHANGED (will requeue)' if nb_ip_changed else 'IP SAME (continue)' }}"
- "Change lines matched: {{ (nb_change_lines | default([])) | join(' | ') if nb_ip_changed else '<none>' }}"
- "OK line: {{ nb_ok_line | default('<none>') }}"
- "Parsed nb_ip={{ nb_ip | default('<n/a>') }}"
- "Reason: {{ nb_change_reason }}"
# --- If IP changed → publish a 3s delayed 'sot-updater' task and stop this host ---
- name: "NB preflight | Publish delayed requeue (3s) and stop"