From c2bd606eb763622f2975d030cb92f71229821f52 Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 22 Oct 2025 22:12:02 +0300 Subject: [PATCH] 2211 --- files/ansible-playbooks/update-indoor.yml | 34 +++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/files/ansible-playbooks/update-indoor.yml b/files/ansible-playbooks/update-indoor.yml index 5759a73..310117f 100644 --- a/files/ansible-playbooks/update-indoor.yml +++ b/files/ansible-playbooks/update-indoor.yml @@ -482,17 +482,24 @@ msg: "DEV2 firmux={{ (dev2_firmux.stdout | default('')) | trim }}" # ---------------------------- Normalize rebootin early (HOURS) ---------------------------- - # Normalize 'rebootin' (detect 'now' or integer HOURS) + # Accept: "", "now", "immediate", numeric (4), numeric string ("4"), or "4h" - name: Normalize rebootin detect now or integer HOURS delegate_to: localhost ansible.builtin.set_fact: _reboot_raw: "{{ rebootin | default('') | string | trim | lower }}" _reboot_is_now: "{{ (rebootin | default('') | string | trim | lower) in ['', 'now', 'immediate'] }}" - _reboot_is_int: "{{ (rebootin | default('') | string | trim) is match('^\\d+$') }}" + _reboot_is_numtype: "{{ (rebootin | type_debug) in ['int','float'] }}" + _reboot_is_digitstr: "{{ (rebootin | default('') | string | trim) is match('^\\d+$') }}" + _reboot_is_hsuffix: "{{ (rebootin | default('') | string | trim | lower) is match('^\\d+h$') }}" _reboot_hours: >- {{ - 0 if ((rebootin | default('') | string | trim | lower) in ['', 'now', 'immediate']) - else (rebootin | int if ((rebootin | default('') | string | trim) is match('^\\d+$')) else -1) + 0 + if ((rebootin | default('') | string | trim | lower) in ['', 'now', 'immediate']) + else ( (rebootin | int) + if ((rebootin | type_debug) in ['int','float']) + else ( (_reboot_raw | regex_replace('h$', '') | int) + if (_reboot_is_digitstr or _reboot_is_hsuffix) + else -1)) }} - name: Debug reboot normalization detail @@ -501,7 +508,9 @@ msg: - "_reboot_raw={{ _reboot_raw | default('UNSET') }}" - "_reboot_is_now={{ _reboot_is_now | default('UNSET') }}" - - "_reboot_is_int={{ _reboot_is_int | default('UNSET') }}" + - "_reboot_is_numtype={{ _reboot_is_numtype | default('UNSET') }}" + - "_reboot_is_digitstr={{ _reboot_is_digitstr | default('UNSET') }}" + - "_reboot_is_hsuffix={{ _reboot_is_hsuffix | default('UNSET') }}" - "_reboot_hours={{ _reboot_hours | default('UNSET') }}" - name: Warn if rebootin was not provided by consumer (debug only) @@ -510,19 +519,17 @@ ansible.builtin.debug: msg: "WARNING: rebootin is empty or missing. Consumer likely did not pass -e rebootin=." - - # Compute reboot flags and *final* seconds value with the 20s grace rule - # Rule: now/empty -> 20s; integer <=0 -> 20s; integer >0 -> hours*3600 - - name: Compute reboot flags requested and seconds with 20s grace + # Compute reboot flags and *final* seconds. + # Rule: now/empty/0 -> 20s grace; hours>0 -> hours*3600 (no extra 20s). + - name: Compute reboot flags requested and seconds with proper conversion delegate_to: localhost ansible.builtin.set_fact: - _reboot_requested: "{{ _reboot_is_now or _reboot_is_int }}" + _reboot_requested: "{{ _reboot_is_now or (_reboot_hours | int) >= 0 }}" _reboot_seconds: >- {{ 20 - if _reboot_is_now - else (20 if ((_reboot_is_int | bool) and ((_reboot_hours | int) <= 0)) - else ((_reboot_hours | int) * 3600)) + if (_reboot_is_now or ((_reboot_hours | int) == 0)) + else ((_reboot_hours | int) * 3600) }} # Derive minutes from seconds @@ -531,7 +538,6 @@ ansible.builtin.set_fact: _reboot_minutes: "{{ ((_reboot_seconds | int) // 60) if (_reboot_seconds | int) > 0 else 0 }}" - - name: Debug reboot plan summary delegate_to: localhost ansible.builtin.debug: