This commit is contained in:
2025-11-04 16:46:04 +02:00
parent 7f2f622124
commit 83b882e670

View File

@@ -79,7 +79,6 @@
- "{{ (nb_preflight.stderr_lines | default(['<no stderr>'])) }}" - "{{ (nb_preflight.stderr_lines | default(['<no stderr>'])) }}"
- "raw stdout (joined): {{ nb_preflight.stdout | default('') | trim }}" - "raw stdout (joined): {{ nb_preflight.stdout | default('') | trim }}"
# --- Parse the OK line robustly (token-based) --- # --- Parse the OK line robustly (token-based) ---
- name: "NB preflight | Parse OK line (token)" - name: "NB preflight | Parse OK line (token)"
when: nb_script.stat.exists when: nb_script.stat.exists
@@ -110,7 +109,6 @@
nb_small: "{{ nb_kv.get('small', '') }}" nb_small: "{{ nb_kv.get('small', '') }}"
nb_ok_line: "{{ nb_ok_line }}" nb_ok_line: "{{ nb_ok_line }}"
# --- Detect "cloud vs NetBox (before update) was different" (regex-free, robust) # --- Detect "cloud vs NetBox (before update) was different" (regex-free, robust)
- name: "NB preflight | Detect whether IP changed (pre-update)" - name: "NB preflight | Detect whether IP changed (pre-update)"
when: nb_script.stat.exists when: nb_script.stat.exists
@@ -126,21 +124,40 @@
nb_ip_changed: "{{ reason != 'none' }}" nb_ip_changed: "{{ reason != 'none' }}"
nb_change_reason: "{{ reason }}" nb_change_reason: "{{ reason }}"
# --- Detect cloud error (network/HTTP/500s) ---
- name: "NB preflight | Detect cloud error"
when: nb_script.stat.exists
delegate_to: localhost
vars:
out: "{{ (nb_preflight.stdout | default('') | regex_replace('\r','')) }}"
set_fact:
nb_cloud_error: "{{ (nb_preflight.rc | default(1)) != 0 or ('FAIL ' in out) }}"
nb_cloud_error_rc: "{{ nb_preflight.rc | default('n/a') }}"
- name: "NB preflight | Verdict" - name: "NB preflight | Verdict"
when: nb_script.stat.exists when: nb_script.stat.exists
delegate_to: localhost delegate_to: localhost
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "NB preflight verdict: {{ 'IP CHANGED (will requeue)' if nb_ip_changed else 'IP SAME (continue)' }}" - >-
- "Reason: {{ nb_change_reason }}" NB preflight verdict:
{{ 'IP CHANGED (will requeue)' if (nb_ip_changed|default(false)) else
('CLOUD ERROR (will requeue)' if (nb_cloud_error|default(false)) else
'OK (continue)') }}
- "Reason (IP): {{ nb_change_reason | default('none') }}"
- "rc={{ nb_cloud_error_rc | default('n/a') }}"
- >-
First FAIL line (if any):
{{
((nb_preflight.stdout | default('')) | regex_replace('\r','')).
split('\n') | select('search','^FAIL ') | list | first | default('<none>')
}}
# --- If IP changed or cloud errored → publish a 3s delayed 'sot-updater' task and stop this host ---
- name: "NB preflight | Publish delayed requeue (3s) and stop" - name: "NB preflight | Publish delayed requeue (3s) and stop"
when: when:
- nb_script.stat.exists - nb_script.stat.exists
- nb_ip_changed | default(false) - (nb_ip_changed | default(false)) or (nb_cloud_error | default(false))
delegate_to: localhost delegate_to: localhost
uri: uri:
url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/app/deviceconfig.delayed/publish" url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/app/deviceconfig.delayed/publish"
@@ -149,7 +166,7 @@
password: "change_me" password: "change_me"
force_basic_auth: true force_basic_auth: true
status_code: 200 status_code: 200
return_content: yes # <-- make response body available return_content: yes
headers: headers:
content-type: "application/json" content-type: "application/json"
body_format: json body_format: json
@@ -168,7 +185,7 @@
- name: "NB preflight | Log requeue publish response" - name: "NB preflight | Log requeue publish response"
when: when:
- nb_script.stat.exists - nb_script.stat.exists
- nb_ip_changed | default(false) - (nb_ip_changed | default(false)) or (nb_cloud_error | default(false))
delegate_to: localhost delegate_to: localhost
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
@@ -180,19 +197,18 @@
- name: "NB preflight | Stop further tasks for this host" - name: "NB preflight | Stop further tasks for this host"
when: when:
- nb_script.stat.exists - nb_script.stat.exists
- nb_ip_changed | default(false) - (nb_ip_changed | default(false)) or (nb_cloud_error | default(false))
meta: end_host meta: end_host
# --- If IP did not change → optional 1s pause, then continue normally --- # --- If neither IP changed nor cloud error → optional 1s pause, then continue normally ---
- name: "NB preflight | Pause 1s" - name: "NB preflight | Pause 1s"
when: when:
- nb_script.stat.exists - nb_script.stat.exists
- not (nb_ip_changed | default(false)) - not ((nb_ip_changed | default(false)) or (nb_cloud_error | default(false)))
delegate_to: localhost delegate_to: localhost
ansible.builtin.pause: ansible.builtin.pause:
seconds: 1 seconds: 1
tasks: tasks:
- name: "⚙️ Start | Dev1 banner → tunnel/auth → Dev2 firmux (telemetry mode)" - name: "⚙️ Start | Dev1 banner → tunnel/auth → Dev2 firmux (telemetry mode)"
debug: debug:
@@ -279,7 +295,6 @@
failed_when: false failed_when: false
ignore_errors: true ignore_errors: true
- name: Refresh ARP #1 - name: Refresh ARP #1
raw: "{{ pathprefix }} arping -U -I {{ arping_iface }} {{ dev2_side_ip_addr }} -c 3" raw: "{{ pathprefix }} arping -U -I {{ arping_iface }} {{ dev2_side_ip_addr }} -c 3"
failed_when: false failed_when: false
@@ -425,7 +440,6 @@
failed_when: false failed_when: false
ignore_errors: true ignore_errors: true
# ----------------------- DEV2 firmux (simplified, literal) ----------------------- # ----------------------- DEV2 firmux (simplified, literal) -----------------------
- name: Dev2 | Read /usr/lib/release/firmux - name: Dev2 | Read /usr/lib/release/firmux
when: tunnel_ok | default(false) and dev2_passfile_used != 'NONE' when: tunnel_ok | default(false) and dev2_passfile_used != 'NONE'