From b1d1fc833c220639a166d04dfcaa4130cb193528 Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 25 Feb 2026 17:33:45 +0200 Subject: [PATCH] 1733 --- files/ansible-playbooks/sot-updater.yml | 184 ++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 5c83aba..87f333b 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -36,6 +36,10 @@ rmq_exchange: "{{ lookup('env','RMQ_EXCHANGE') | default('controls', true) }}" control_queue: "{{ lookup('env','CONTROLQUEUE') | default('queue_controls', true) }}" + # NetBox API (delta compare; user may override) + netbox_url: "{{ lookup('env','NB') | default('', true) }}" + netbox_token: "{{ lookup('env','TOKEN') | default('', true) }}" + # --- Retry attempt tracking (default 0 if missing) --- requeue_attempt: "{{ (lookup('env','REQUEUE_ATTEMPT') | default('0', true)) | int }}" @@ -273,6 +277,45 @@ pause: seconds: 1 + + # ----------------------- NetBox baseline (for delta compare) ----------------------- + - name: NB baseline | Init baseline facts + delegate_to: localhost + set_fact: + nb_baseline_ok: false + nb_device_id: "" + nb_custom_fields_current: {} + changed_when: false + + - name: NB baseline | Read id and custom_fields (fields) + when: + - (netbox_url | default('') | length) > 0 + - (netbox_token | default('') | length) > 0 + delegate_to: localhost + uri: + url: "{{ netbox_url }}/api/dcim/devices/?name={{ inventory_hostname|urlencode }}&fields=id,custom_fields&limit=1" + method: GET + headers: + Authorization: "Token {{ netbox_token }}" + content-type: "application/json" + return_content: yes + status_code: 200 + register: nb_cf_lookup + changed_when: false + failed_when: false + + - name: NB baseline | Set baseline facts + when: + - nb_cf_lookup is defined + - (nb_cf_lookup.status | default(0)) == 200 + - (nb_cf_lookup.json.results | default([]) | length) > 0 + delegate_to: localhost + set_fact: + nb_baseline_ok: true + nb_device_id: "{{ nb_cf_lookup.json.results[0].id | default('') }}" + nb_custom_fields_current: "{{ nb_cf_lookup.json.results[0].custom_fields | default({}) }}" + changed_when: false + tasks: - name: "⚙️ Start | Dev1 banner → tunnel/auth → Dev2 firmux (telemetry mode)" debug: @@ -288,6 +331,14 @@ scan_fail: [] changed_when: false + + # ----------------------- Delta tracking (skip unchanged custom fields) ----------------------- + - name: Delta tracking | Init diff flag + delegate_to: localhost + set_fact: + non_ts_diff_found: false + changed_when: false + # ----------------------- Temp IP on DEV1 ----------------------- - name: Add temporary IP on DEV1 raw: "{{ pathprefix }} ip a add {{ dev2_side_ip }} dev {{ dev1_iface }}" @@ -457,6 +508,8 @@ changed_when: false - name: Publish Dev1 fw_version + when: + - (not (nb_baseline_ok | default(false))) or (((dev1_fw_clean if (dev1_fw_clean|length>0) else 'unavailable')) != (nb_custom_fields_current.get('fw_version'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -479,6 +532,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed fw_version + when: + - (not (nb_baseline_ok | default(false))) or (((dev1_fw_clean if (dev1_fw_clean|length>0) else 'unavailable')) != (nb_custom_fields_current.get('fw_version'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 bootbanks backup firmux → fw_version_backup ----------------------- - name: Dev1 | Read bootbanks backup firmux via jq delegate_to: localhost @@ -524,6 +586,8 @@ changed_when: false - name: Publish Dev1 fw_version_backup + when: + - (not (nb_baseline_ok | default(false))) or ((fw_version_backup_value) != (nb_custom_fields_current.get('fw_version_backup'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -547,6 +611,15 @@ changed_when: false + + - name: Delta tracking | Mark changed fw_version_backup + when: + - (not (nb_baseline_ok | default(false))) or ((fw_version_backup_value) != (nb_custom_fields_current.get('fw_version_backup'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 SSID count (jq-based, schema-aware) ----------------------- - name: Dev1 | SSID profiles summary via jq (AP radios only) delegate_to: localhost @@ -593,6 +666,8 @@ msg: "multissidfix_value={{ multissidfix_value }}" - name: Publish Dev1 multissidfix custom field + when: + - (not (nb_baseline_ok | default(false))) or ((multissidfix_value) != (nb_custom_fields_current.get('multissidfix'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -615,6 +690,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed multissidfix + when: + - (not (nb_baseline_ok | default(false))) or ((multissidfix_value) != (nb_custom_fields_current.get('multissidfix'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 scroll24.sh check & publish ----------------------- - name: Dev1 | Check scroll24.sh presence delegate_to: localhost @@ -758,6 +842,8 @@ - "scroll24_value={{ scroll24_value | default('n/a') }}" - name: Publish Dev1 scroll24 custom field + when: + - (not (nb_baseline_ok | default(false))) or ((scroll24_value) != (nb_custom_fields_current.get('scroll24'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -780,6 +866,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed scroll24 + when: + - (not (nb_baseline_ok | default(false))) or ((scroll24_value) != (nb_custom_fields_current.get('scroll24'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 wifidebug.sh check & publish ----------------------- - name: Dev1 | Check wifidebug.sh presence delegate_to: localhost @@ -872,6 +967,8 @@ changed_when: false - name: Publish Dev1 connstats custom field + when: + - (not (nb_baseline_ok | default(false))) or ((connstats_value) != (nb_custom_fields_current.get('connstats'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -894,6 +991,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed connstats + when: + - (not (nb_baseline_ok | default(false))) or ((connstats_value) != (nb_custom_fields_current.get('connstats'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Scan tracking: Dev1 wifidebug ----------------------- - name: Scan tracking | Dev1 wifidebug outcome delegate_to: localhost @@ -902,6 +1008,8 @@ changed_when: false - name: Publish Dev1 wifidebug custom field + when: + - (not (nb_baseline_ok | default(false))) or ((wifidebug_value) != (nb_custom_fields_current.get('wifidebug'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -924,6 +1032,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed wifidebug + when: + - (not (nb_baseline_ok | default(false))) or ((wifidebug_value) != (nb_custom_fields_current.get('wifidebug'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 fw_printenv size → cpe_bootenv ----------------------- - name: Dev1 | Read fw_printenv size (line count) delegate_to: localhost @@ -960,6 +1077,8 @@ changed_when: false - name: Publish Dev1 cpe_bootenv custom field + when: + - (not (nb_baseline_ok | default(false))) or ((cpe_bootenv_value) != (nb_custom_fields_current.get('cpe_bootenv'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -982,6 +1101,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed cpe_bootenv + when: + - (not (nb_baseline_ok | default(false))) or ((cpe_bootenv_value) != (nb_custom_fields_current.get('cpe_bootenv'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev1 hostname (for Dev2 mismatch check) ----------------------- - name: Dev1 | Read kernel hostname delegate_to: localhost @@ -1423,6 +1551,8 @@ changed_when: false - name: Publish Dev2 indoor_fwver + when: + - (not (nb_baseline_ok | default(false))) or (((indoor_fw_norm if indoor_fw_norm|length>0 else 'unavailable')) != (nb_custom_fields_current.get('indoor_fwver'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -1446,6 +1576,15 @@ changed_when: false + + - name: Delta tracking | Mark changed indoor_fwver + when: + - (not (nb_baseline_ok | default(false))) or (((indoor_fw_norm if indoor_fw_norm|length>0 else 'unavailable')) != (nb_custom_fields_current.get('indoor_fwver'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev2 bootbanks backup firmux → indoor_fwver_backup ----------------------- - name: Dev2 | Read bootbanks backup firmux (tunnel) when: @@ -1572,6 +1711,8 @@ changed_when: false - name: Publish Dev2 indoor_fwver_backup + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_fwver_backup_value) != (nb_custom_fields_current.get('indoor_fwver_backup'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -1595,6 +1736,15 @@ changed_when: false + + - name: Delta tracking | Mark changed indoor_fwver_backup + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_fwver_backup_value) != (nb_custom_fields_current.get('indoor_fwver_backup'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev2 fw_printenv size → indoor_bootenv ----------------------- - name: Dev2 | Read fw_printenv size (tunnel) when: @@ -1715,6 +1865,8 @@ changed_when: false - name: Publish Dev2 indoor_bootenv custom field + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_bootenv_value) != (nb_custom_fields_current.get('indoor_bootenv'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -1737,6 +1889,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed indoor_bootenv + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_bootenv_value) != (nb_custom_fields_current.get('indoor_bootenv'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- Dev2 hostname check + publish ----------------------- - name: Dev2 | Read hostname (tunnel) when: @@ -1871,6 +2032,8 @@ - "indoor_hostname_value={{ indoor_hostname_value | default('n/a') }}" - name: Publish Dev2 indoor_hostname custom field + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_hostname_value) != (nb_custom_fields_current.get('indoor_hostname'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -1894,6 +2057,15 @@ changed_when: false + + - name: Delta tracking | Mark changed indoor_hostname + when: + - (not (nb_baseline_ok | default(false))) or ((indoor_hostname_value) != (nb_custom_fields_current.get('indoor_hostname'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + - name: Indoor | Normalize Dev2 passfile facts (avoid undefined) delegate_to: localhost set_fact: @@ -2051,6 +2223,8 @@ - "selected indoor_ip={{ indoor_ip_value | default('') | trim }}" - name: Publish Dev2 indoor_ip custom field + when: + - (not (nb_baseline_ok | default(false))) or (((indoor_ip_value | default('na') | trim)) != (nb_custom_fields_current.get('indoor_ip'))) delegate_to: localhost uri: url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" @@ -2073,6 +2247,15 @@ payload_encoding: "string" changed_when: false + + - name: Delta tracking | Mark changed indoor_ip + when: + - (not (nb_baseline_ok | default(false))) or (((indoor_ip_value | default('na') | trim)) != (nb_custom_fields_current.get('indoor_ip'))) + delegate_to: localhost + set_fact: + non_ts_diff_found: true + changed_when: false + # ----------------------- SOT timestamp (container local time) → sot_ts ----------------------- - name: SOT ts | Get container timestamp delegate_to: localhost @@ -2128,6 +2311,7 @@ # ----------------------- Final journal: scan status ----------------------- - name: Journal final scan status (success / partial / fail) + when: non_ts_diff_found | default(false) delegate_to: localhost vars: _ok_n: "{{ (scan_ok | default([])) | length }}"