This commit is contained in:
2025-11-05 20:52:35 +02:00
parent 7a99d4a10c
commit 2e503ce59e

View File

@@ -79,6 +79,60 @@
- "{{ (nb_preflight.stderr_lines | default(['<no stderr>'])) }}"
- "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