From 83aba97ad8ccd3a94eb2204e1560c0301117ebc8 Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 19 Nov 2025 11:24:23 +0200 Subject: [PATCH] 1124 --- files/ansible-playbooks/sot-updater.yml | 177 +++++++++++++++++++++--- 1 file changed, 155 insertions(+), 22 deletions(-) diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 40f5057..1ff298e 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -146,7 +146,7 @@ {{ dict( nb_tokens - | select('match', '^[a-zA-Z_]+=') + | select('match', '^[a-zA-Z_]+=') # only tokens with '=' | map('split', '=', 1) | map('list') ) @@ -444,7 +444,6 @@ - name: Dev1 | Normalize strict SSID count delegate_to: localhost set_fact: - # Keep as text; we’ll cast with | int when using it ssid_strict_count: "{{ (ssid_strict_count_raw.stdout | default('0')) | trim }}" - name: Dev1 | Decide if strict count usable @@ -472,7 +471,6 @@ when: not ssid_strict_ok | default(false) delegate_to: localhost set_fact: - # Also keep as text ssid_fallback_count: "{{ (ssid_fallback_count_raw.stdout | default('0')) | trim }}" - name: Dev1 | Compute final SSID count @@ -508,7 +506,6 @@ debug: msg: "multissidfix_value={{ multissidfix_value }}" - - name: Publish Dev1 multissidfix custom field delegate_to: localhost uri: @@ -532,6 +529,154 @@ payload_encoding: "string" changed_when: false + # ----------------------- Dev1 scroll24.sh check & publish ----------------------- + - name: Dev1 | Check scroll24.sh presence + delegate_to: localhost + shell: | + sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} \ + "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" \ + "test -f /root/scroll24.sh && echo present || echo missing" + register: scroll24_present_raw + changed_when: false + failed_when: false + ignore_errors: true + + - name: Dev1 | Set scroll24 presence fact + delegate_to: localhost + set_fact: + scroll24_present: "{{ (scroll24_present_raw.stdout | default('') | trim) == 'present' }}" + + - name: Dev1 | Read scroll24.sh version line (may be empty -> v1) + when: scroll24_present | default(false) + delegate_to: localhost + shell: | + sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} \ + "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" \ + "grep -i 'scroll24_version' /root/scroll24.sh 2>/dev/null | head -n1 || true" + register: scroll24_ver_line + changed_when: false + failed_when: false + ignore_errors: true + + - name: Dev1 | Normalize scroll24 version + when: scroll24_present | default(false) + delegate_to: localhost + set_fact: + scroll24_ver_clean: >- + {{ + ( + scroll24_ver_line.stdout | default('') | trim + ) + | regex_replace('^.*=', '') + | trim + if (scroll24_ver_line is defined + and (scroll24_ver_line.stdout | default('') | trim | length) > 0) + else 'v1' + }} + + - name: Dev1 | Read scroll24 crontab entry (first match) + delegate_to: localhost + shell: | + sshpass -p '{{ dev1_pass }}' ssh {{ ssh_opts_common }} \ + "{{ dev1_user }}@{{ ansible_host|default(inventory_hostname) }}" \ + "crontab -l 2>/dev/null | grep 'scroll24.sh' | head -n1 || true" + register: scroll24_cron_raw + changed_when: false + failed_when: false + ignore_errors: true + + - name: Dev1 | Normalize scroll24 cron line + delegate_to: localhost + set_fact: + scroll24_cron_line: "{{ scroll24_cron_raw.stdout | default('') | trim }}" + + - name: Dev1 | Derive scroll24 schedule summary + delegate_to: localhost + vars: + cron_parts: "{{ scroll24_cron_line.split() if scroll24_cron_line|length > 0 else [] }}" + min_field: "{{ cron_parts[0] if cron_parts|length > 0 else '' }}" + hour_field: "{{ cron_parts[1] if cron_parts|length > 1 else '' }}" + every_n_minutes: >- + {{ + (min_field is match('^\\*/[0-9]+$')) and (hour_field == '*') + }} + every_n_hours: >- + {{ + hour_field is match('^\\*/[0-9]+$') + }} + interval_value: >- + {%- if every_n_minutes -%} + {{ min_field.split('/')[1] }} + {%- elif every_n_hours -%} + {{ hour_field.split('/')[1] }} + {%- else -%} + custom + {%- endif -%} + interval_unit: >- + {%- if every_n_minutes -%} + m + {%- elif every_n_hours -%} + h + {%- else -%} + '' + {%- endif -%} + set_fact: + scroll24_schedule: >- + {%- if scroll24_cron_line|length == 0 -%} + nocron + {%- elif interval_value == 'custom' or interval_unit|length == 0 -%} + custom + {%- else -%} + {{ interval_value ~ interval_unit }} + {%- endif -%} + + - name: Dev1 | Compute scroll24 value + delegate_to: localhost + set_fact: + scroll24_value: >- + {%- if not (scroll24_present | default(false)) -%} + missing + {%- elif scroll24_schedule == 'nocron' -%} + {{ scroll24_ver_clean | default('v1') }}_nocron + {%- elif scroll24_schedule == 'custom' -%} + {{ scroll24_ver_clean | default('v1') }}_custom + {%- else -%} + {{ scroll24_ver_clean | default('v1') }}_{{ scroll24_schedule }} + {%- endif -%} + + - name: Dev1 | scroll24 debug + delegate_to: localhost + debug: + msg: + - "scroll24_present={{ scroll24_present | default(false) }}" + - "scroll24_ver_clean={{ scroll24_ver_clean | default('n/a') }}" + - "scroll24_cron_line={{ scroll24_cron_line | default('') }}" + - "scroll24_schedule={{ scroll24_schedule | default('n/a') }}" + - "scroll24_value={{ scroll24_value | default('n/a') }}" + + - name: Publish Dev1 scroll24 custom field + delegate_to: localhost + uri: + url: "http://{{ rmq_host }}:{{ rmq_port }}/api/exchanges/{{ rmq_vhost|urlencode }}/{{ rmq_exchange|urlencode }}/publish" + method: POST + user: "{{ rmq_user }}" + password: "{{ rmq_pass }}" + force_basic_auth: true + status_code: 200 + headers: { content-type: "application/json" } + body_format: json + body: + properties: { content_type: "application/json" } + routing_key: "{{ control_queue }}" + payload: "{{ { + 'inscope_device': (ansible_hostname|default(inventory_hostname)), + 'task_name': 'custom_field_set', + 'task_add1': 'scroll24', + 'task_result': scroll24_value + } | to_json }}" + payload_encoding: "string" + changed_when: false + # ----------------------- Dev1 wifidebug.sh check & publish ----------------------- - name: Dev1 | Check wifidebug.sh presence delegate_to: localhost @@ -628,7 +773,6 @@ failed_when: false ignore_errors: true - - name: Set dev2_passfile_used delegate_to: localhost set_fact: @@ -642,7 +786,6 @@ - "dev2_auth.stdout={{ dev2_auth.stdout | default('') | trim }}" - "dev2_passfile_used={{ dev2_passfile_used }}" - - name: Dev2 | Read firmux (tunnel) when: - tunnel_ok | default(false) @@ -661,7 +804,6 @@ failed_when: false ignore_errors: true - # ------ LLDP candidate IP when Dev2 login failed (tunnel up but Dev2 unreachable) ------ - name: Dev1 | Try LLDP-derived Dev2 IP (auth to Dev2 failed) when: @@ -699,7 +841,6 @@ | ternary('yes (10/8)', 'no (not 10/8) or none') }} - # Filter LLDP IP: only keep it if it is 10.0.0.0/8, otherwise blank it out - name: Set LLDP IP fact (10.0.0.0/8 only) when: - tunnel_ok | default(false) @@ -718,7 +859,7 @@ when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 delegate_to: localhost shell: | for f in basicpass basicpass2; do @@ -734,12 +875,11 @@ failed_when: false ignore_errors: true - # Debug 1: what happened during LLDP auth try - name: Dev2 | LLDP path selection debug when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 delegate_to: localhost debug: msg: @@ -751,7 +891,7 @@ when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 delegate_to: localhost set_fact: dev2_passfile_used_lldp: >- @@ -760,23 +900,21 @@ | ternary(dev2_auth_lldp.stdout | default('') | trim, 'NONE') }} - # Debug 2: which passfile will be used for firmux read - name: Dev2 | LLDP passfile decision when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 delegate_to: localhost debug: msg: - "Using passfile for LLDP path: {{ dev2_passfile_used_lldp }}" - # Optional quick TCP check so you see port reachability (no fail) - name: Dev2 | Check TCP/22 reachability (LLDP) when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 delegate_to: localhost shell: "nc -z -w3 {{ lldp_dev2_ip }} 22" register: lldp_ssh_tcp @@ -788,7 +926,7 @@ when: - tunnel_ok | default(false) - dev2_passfile_used == 'NONE' - - lldp_dev2_ip | length > 0 # only if 10.0.0.0/8 + - lldp_dev2_ip | length > 0 - dev2_passfile_used_lldp != 'NONE' delegate_to: localhost shell: | @@ -801,10 +939,6 @@ failed_when: false ignore_errors: true - - - - # ------ Mux: choose whichever firmux output succeeded ------ - name: Dev2 | Choose firmux output (tunnel or LLDP) delegate_to: localhost @@ -823,7 +957,6 @@ - "dev2_firmux_text='{{ dev2_firmux_text | default('') | regex_replace('\n','\\n') }}'" - "indoor_fw_norm='{{ indoor_fw_norm | default('') }}'" - - name: Dev2 | Extract firmware version line delegate_to: localhost run_once: true