diff --git a/files/ansible-playbooks/sot-updater.yml b/files/ansible-playbooks/sot-updater.yml index 887f25d..af285bc 100644 --- a/files/ansible-playbooks/sot-updater.yml +++ b/files/ansible-playbooks/sot-updater.yml @@ -609,51 +609,57 @@ - 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 -%} + shell: | + line="{{ scroll24_cron_line | default('') }}" + + # No crontab hit or no scroll24.sh line + if [ -z "$line" ]; then + echo nocron + exit 0 + fi + + # Extract first 5 cron fields + min="$(echo "$line" | awk '{print $1}')" + hour="$(echo "$line" | awk '{print $2}')" + + # Pattern 1: */N * * * * -> every N minutes + case "$min" in + '*/'*) + n="${min#*/}" + if [ -n "$n" ]; then + echo "${n}m" + exit 0 + fi + ;; + esac + + # Pattern 2: M */H * * * -> every H hours (we ignore the minute) + case "$hour" in + '*/'*) + h="${hour#*/}" + if [ -n "$h" ]; then + echo "${h}h" + exit 0 + fi + ;; + esac + + # Fallback + echo custom + args: + executable: /bin/bash + register: scroll24_sched_raw + changed_when: false + failed_when: false - name: Dev1 | Compute scroll24 value delegate_to: localhost set_fact: + scroll24_schedule: "{{ scroll24_sched_raw.stdout | default('') | trim }}" scroll24_value: >- {%- if not (scroll24_present | default(false)) -%} missing - {%- elif scroll24_schedule == 'nocron' -%} + {%- elif scroll24_schedule in ['nocron', ''] -%} {{ scroll24_ver_clean | default('v1') }}_nocron {%- elif scroll24_schedule == 'custom' -%} {{ scroll24_ver_clean | default('v1') }}_custom @@ -693,6 +699,7 @@ } | to_json }}" payload_encoding: "string" changed_when: false + # ----------------------- Dev1 wifidebug.sh check & publish ----------------------- - name: Dev1 | Check wifidebug.sh presence