This commit is contained in:
2025-11-04 18:13:06 +02:00
parent 1db4bb6cdb
commit 409a75b920

View File

@@ -109,26 +109,75 @@
nb_small: "{{ nb_kv.get('small', '') }}" nb_small: "{{ nb_kv.get('small', '') }}"
nb_ok_line: "{{ nb_ok_line }}" nb_ok_line: "{{ nb_ok_line }}"
# --- Extract upgrade_cmd from nb_onedevice_update.py output (robust, no cross-task vars) --- # --- Extract upgrade_cmd from nb_onedevice_update.py output (prefer stdout_lines; tolerate minor typos) ---
- name: "NB preflight | Capture upgrade_cmd from stdout" - name: "NB preflight | Capture upgrade_cmd from stdout"
when: nb_script.stat.exists when: nb_script.stat.exists
delegate_to: localhost delegate_to: localhost
vars: vars:
stdout_clean: "{{ (nb_preflight.stdout | default('') | regex_replace('\r','')) }}" # Prefer structured lines first
up_line: >- lines_struct: "{{ (nb_preflight.stdout_lines | default([])) }}"
# Fallback to raw joined text if needed
raw_lines: "{{ (nb_preflight.stdout | default('') | regex_replace('\r','')) | split('\n') }}"
all_lines: >-
{{ {{
stdout_clean (lines_struct + raw_lines)
| split('\n')
| map('trim') | map('trim')
| select('match', '^NB:\\s*upgrade_cmd=') | select('truthy')
| list
}}
# Try exact key first
line_exact: >-
{{
all_lines
| select('match', '^NB:\\s*upgrade_cmd\\s*=')
| list | list
| last | last
| default('') | default('')
}} }}
up_val_raw: "{{ up_line | regex_replace('^NB:\\s*upgrade_cmd=\\s*', '') | trim }}" # Tolerate occasional logger typo like "upde_cmd"
line_typo1: >-
{{
('' if line_exact else
(
all_lines
| select('match', '^NB:\\s*upde_cmd\\s*=')
| list
| last
| default('')
)
)
}}
# Broad fallback: any "NB:" line that contains "cmd=" (last resort)
line_broad: >-
{{
('' if line_exact or line_typo1 else
(
all_lines
| select('match', '^NB:.*\\bcmd\\s*=')
| list
| last
| default('')
)
)
}}
# Pick the first non-empty candidate and note which detector hit
chosen_line: "{{ line_exact or line_typo1 or line_broad }}"
chosen_detector: >-
{{
'exact' if line_exact else
('typo1' if line_typo1 else
('broad' if line_broad else 'none'))
}}
# Strip the "NB: <key>=" prefix regardless of which variant matched
up_val_raw: "{{ chosen_line | regex_replace('^NB:\\s*[^=]+=\\s*', '') | trim }}"
# Normalize None/null/empty → ''
up_val_clean: "{{ '' if (up_val_raw | lower) in ['none','null',''] else up_val_raw }}" up_val_clean: "{{ '' if (up_val_raw | lower) in ['none','null',''] else up_val_raw }}"
set_fact: set_fact:
nb_upgrade_cmd_line: "{{ up_line }}" nb_upgrade_cmd_line: "{{ chosen_line }}"
nb_upgrade_cmd_source: "{{ chosen_detector }}"
nb_upgrade_cmd: "{{ up_val_clean }}" nb_upgrade_cmd: "{{ up_val_clean }}"
nb_upgrade_cmd_len: "{{ (up_val_clean | length) }}" nb_upgrade_cmd_len: "{{ (up_val_clean | length) }}"
@@ -137,6 +186,7 @@
delegate_to: localhost delegate_to: localhost
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "upgrade_cmd detector: {{ nb_upgrade_cmd_source | default('none') }}"
- "upgrade_cmd line: {{ nb_upgrade_cmd_line | default('<none>') }}" - "upgrade_cmd line: {{ nb_upgrade_cmd_line | default('<none>') }}"
- "upgrade_cmd parsed: '{{ nb_upgrade_cmd | default('') }}' (len={{ nb_upgrade_cmd_len | default(0) }})" - "upgrade_cmd parsed: '{{ nb_upgrade_cmd | default('') }}' (len={{ nb_upgrade_cmd_len | default(0) }})"