From 3ce31fb57131ca63703e9c08a777b2506a876783 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 12 Feb 2026 15:54:10 +0200 Subject: [PATCH] 1554 --- .../ansible-playbooks/afterupgrade_check.yml | 168 ++++++++++++++++++ .../ansible-playbooks/update-rebootin224.yml | 22 +++ 2 files changed, 190 insertions(+) diff --git a/files/ansible-playbooks/afterupgrade_check.yml b/files/ansible-playbooks/afterupgrade_check.yml index e282ff4..660243a 100644 --- a/files/ansible-playbooks/afterupgrade_check.yml +++ b/files/ansible-playbooks/afterupgrade_check.yml @@ -254,6 +254,118 @@ register: rmq_cleanup_success changed_when: (rmq_cleanup_success.json is defined) and (rmq_cleanup_success.json.routed | default(false) | bool) + - name: Success | Pause before NetBox wrapup custom fields + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_success_payload is defined + + - name: Success | Publish action_state done + when: journal_success_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_state', 'task_result': 'done' }} | to_json }}" + payload_encoding: "string" + changed_when: false + + - name: Success | Pause before NetBox wrapup custom fields + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_success_payload is defined + + - name: Success | Clear action_restart_timestamp + when: journal_success_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_restart_timestamp', 'task_result': '' }} | to_json }}" + payload_encoding: "string" + changed_when: false + + - name: Success | Pause before NetBox wrapup custom fields + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_success_payload is defined + + - name: Success | Clear action_next + when: journal_success_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_next', 'task_result': '' }} | to_json }}" + payload_encoding: "string" + changed_when: false + + - name: Success | Pause before NetBox wrapup custom fields + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_success_payload is defined + + - name: Success | Clear action_next_timestamp + when: journal_success_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_next_timestamp', 'task_result': '' }} | to_json }}" + payload_encoding: "string" + changed_when: false + # Mismatch: reachable & banner read, but not equal to target_version - name: Build mismatch journal payload when: nc_probe.rc == 0 and banner_probe.rc == 0 and not (version_match | bool) @@ -289,6 +401,34 @@ register: rmq_j_mismatch changed_when: (rmq_j_mismatch.json is defined) and (rmq_j_mismatch.json.routed | default(false) | bool) + - name: Failure | Pause before action_state failed + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_mismatch_payload is defined + + - name: Failure | Publish action_state failed (mismatch) + when: journal_mismatch_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_state', 'task_result': 'failed' }} | to_json }}" + payload_encoding: "string" + changed_when: false + # SSH error path: TCP OK, but SSH failed - name: Build failure journal payload (ssh error) + mark retry when: nc_probe.rc == 0 and banner_probe.rc != 0 @@ -375,6 +515,34 @@ register: rmq_j_gaveup changed_when: (rmq_j_gaveup.json is defined) and (rmq_j_gaveup.json.routed | default(false) | bool) + - name: Failure | Pause before action_state failed (gave up) + ansible.builtin.pause: + seconds: 1 + delegate_to: localhost + changed_when: false + when: journal_gaveup_payload is defined + + - name: Failure | Publish action_state failed (gave up) + when: journal_gaveup_payload is defined + 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': 'custom_field_set', 'task_add1': 'action_state', 'task_result': 'failed' }} | to_json }}" + payload_encoding: "string" + changed_when: false + - name: Stop host after final gave-up when: journal_gaveup_payload is defined ansible.builtin.meta: end_host diff --git a/files/ansible-playbooks/update-rebootin224.yml b/files/ansible-playbooks/update-rebootin224.yml index dec68fb..5e802de 100644 --- a/files/ansible-playbooks/update-rebootin224.yml +++ b/files/ansible-playbooks/update-rebootin224.yml @@ -870,6 +870,28 @@ delegate_to: localhost when: is_run_by_effective == 'scheduler' + + - name: Scheduler | Compute action_restart_timestamp (unix seconds) when rebootin == 0 + ansible.builtin.set_fact: + action_restart_timestamp: "{{ lookup('pipe','date -u +%s') | int }}" + changed_when: false + delegate_to: localhost + when: + - is_run_by_effective == 'scheduler' + - reboot_seconds is defined + - (reboot_seconds | int) == 0 + + - name: Scheduler | Compute action_restart_timestamp (unix seconds) when reboot scheduled + ansible.builtin.set_fact: + action_restart_timestamp: "{{ (lookup('pipe','date -u +%s') | int) + (reboot_seconds | int) }}" + changed_when: false + delegate_to: localhost + when: + - is_run_by_effective == 'scheduler' + - reboot_seconds is defined + - (reboot_seconds | int) > 0 + + - name: Scheduler | Compute action_restart_timestamp (unix seconds) when reboot scheduled ansible.builtin.set_fact: action_restart_timestamp: "{{ (lookup('pipe','date -u +%s') | int) + (reboot_seconds | int) }}"