From 2e503ce59edc1d31423c6f68c1e731fd4708a2cf Mon Sep 17 00:00:00 2001 From: pavel Date: Wed, 5 Nov 2025 20:52:35 +0200 Subject: [PATCH] 20:52 --- .../sot-updater-upgradecmd.yml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/files/ansible-playbooks/sot-updater-upgradecmd.yml b/files/ansible-playbooks/sot-updater-upgradecmd.yml index 94c7eda..5ece4a1 100644 --- a/files/ansible-playbooks/sot-updater-upgradecmd.yml +++ b/files/ansible-playbooks/sot-updater-upgradecmd.yml @@ -79,6 +79,60 @@ - "{{ (nb_preflight.stderr_lines | default([''])) }}" - "raw stdout (joined): {{ nb_preflight.stdout | default('') | trim }}" + # --- Abort early if cloud is unavailable (avoid requeue loops) --- + - name: "NB preflight | Detect cloud failure from script output" + when: nb_script.stat.exists + delegate_to: localhost + vars: + _lines: >- + {{ (nb_preflight.stdout | default('') | regex_replace('\r','')) + | split('\n') | map('trim') | list }} + _cloud_fail_line: >- + {{ (_lines | select('match', '^FAIL\\s+Cloud\\b') | list | last | default('')) }} + ansible.builtin.set_fact: + cloud_fail_line: "{{ _cloud_fail_line }}" + cloud_ok: "{{ ( _cloud_fail_line | length ) == 0 }}" + + - name: "NB preflight | Journal + soft-close when cloud is unavailable" + when: + - nb_script.stat.exists + - not cloud_ok | default(true) + delegate_to: localhost + ansible.builtin.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': 'journal_add', + 'task_result': ( + 'preflight abort: cloud unavailable; closing without requeue. ' + ~ (cloud_fail_line | default('')) + ) + } | to_json }}" + payload_encoding: "string" + register: rmq_cloud_unavail + changed_when: (rmq_cloud_unavail.json is defined) and (rmq_cloud_unavail.json.routed | default(false) | bool) + failed_when: false + + - name: "NB preflight | Stop host due to cloud unavailability" + when: + - nb_script.stat.exists + - not cloud_ok | default(true) + ansible.builtin.meta: end_host + + + # --- Debug-only: capture the exact upgrade_cmd line and stop the play --- - name: "NB preflight | Extract exact upgrade_cmd line" when: nb_script.stat.exists