This commit is contained in:
2026-01-20 07:01:44 +02:00
parent 1d837f66ef
commit 217ff735a2

View File

@@ -4,6 +4,18 @@
# Phase 2: Refresh ansible_host from nb_ip, reset_connection
# Phase 3: Run full sot-updater-current.yml
- hosts: all
gather_facts: no
vars:
rmq_host: "{{ lookup('env','RMQ_HOST') | default('10.210.12.2', true) }}"
rmq_port: "{{ lookup('env','RMQ_PORT') | default('15672', true) }}"
rmq_user: "{{ lookup('env','RMQ_USER') | default('admin', true) }}"
rmq_pass: "{{ lookup('env','RMQ_PASS') | default('change_me', true) }}"
rmq_vhost: "{{ lookup('env','RMQ_VHOST') | default('app', true) }}"
rmq_exchange: "{{ lookup('env','RMQ_EXCHANGE') | default('controls', true) }}"
control_queue: "{{ lookup('env','CONTROLQUEUE') | default('queue_controls', true) }}"
tasks: []
- import_playbook: sot-updater-iponly.yml
vars:
sot_wrapper_mode: true
@@ -18,6 +30,7 @@
vars:
_lines: "{{ (nb_preflight.stdout_lines | default([])) | map('regex_replace','\r','') | map('trim') | list }}"
_ok_line: "{{ (_lines | select('match','^OK\\s+') | list | last | default('')) }}"
_fail_line: "{{ (_lines | select('match','^FAIL\\s+') | list | last | default('')) }}"
_ip_raw: "{{ _ok_line | regex_search('(?:^|\\s)ip=([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(?:\\s|$)', '\\1') | default('') }}"
_ip: >-
{%- if _ip_raw is string -%}
@@ -29,6 +42,7 @@
{%- endif -%}
set_fact:
wrapper_ok_line: "{{ _ok_line }}"
wrapper_fail_line: "{{ _fail_line }}"
wrapper_nb_ip: "{{ _ip | trim }}"
@@ -36,8 +50,42 @@
ansible.builtin.debug:
msg:
- "wrapper_ok_line='{{ wrapper_ok_line }}'"
- "wrapper_fail_line='{{ wrapper_fail_line | default('') }}'"
- "wrapper_nb_ip='{{ wrapper_nb_ip }}'"
# ----------------------- Option A: Cloud offline / no IP -> Journal + stop cleanly -----------------------
- name: "Wrapper | Journal: device not online in cloud (skip full scan)"
delegate_to: localhost
when: (wrapper_fail_line | default('') | length) > 0
vars:
_journal_msg: >-
during sot-updater scan the device was not online in cloud (no IP). please try later.
details: {{ wrapper_fail_line | default('') }}
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': _journal_msg
} | to_json }}"
payload_encoding: "string"
changed_when: false
- name: "Wrapper | Stop host after cloud-offline journal (no full scan)"
when: (wrapper_fail_line | default('') | length) > 0
meta: end_host
# ----------------------- Normal path: we have OK ip=... -> proceed -----------------------
- name: "Wrapper | Assert IP extracted successfully"
ansible.builtin.assert:
that:
@@ -48,6 +96,7 @@
fail_msg: >-
Wrapper stop: could not extract IP from nb_onedevice_update.py output.
ok_line='{{ wrapper_ok_line | default('') }}'
fail_line='{{ wrapper_fail_line | default('') }}'
stdout_tail={{ (nb_preflight.stdout_lines | default([]))[-12:] }}
- name: "Wrapper | Override ansible_host to refreshed IP ({{ wrapper_nb_ip }})"