feat: rework notification
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
force_basic_auth: true
|
||||
validate_certs: false
|
||||
register: _firmware_status
|
||||
until: _firmware_status.json.status != 'none'
|
||||
until: _firmware_status.json.status_msg != "Firmware status requires to check for update first to provide more information."
|
||||
retries: 10
|
||||
delay: 2
|
||||
|
||||
@@ -55,41 +55,42 @@
|
||||
ansible.builtin.set_fact:
|
||||
firmware_action: "{{ opnsense_action | default('update')}}"
|
||||
firmware_status: "{{ _firmware_status.json.status }}"
|
||||
firmware_status_msg: "{{ _firmware_status.json.status_msg }}"
|
||||
firmware_current_version: "{{ _firmware_status.json.product.product_version | default('unknown') }}"
|
||||
firmware_product_series: "{{ _firmware_status.json.product.product_series | default('unknown') }}"
|
||||
firmware_update_version: "{{ _firmware_status.json.upgrade_packages | selectattr('name', 'equalto', 'opnsense') | map(attribute='new_version') | first | default('') }}"
|
||||
firmware_upgrade_version: "{{ _firmware_status.json.upgrade_major_version | default('unknown') }}"
|
||||
firmware_upgrade_message: "{{ _firmware_status.json.upgrade_major_message | regex_replace('<[^>]+>', ' ') | regex_replace('\\s{2,}', ' ') | trim | default('') }}"
|
||||
update_needs_reboot: "{{ _firmware_status.json.needs_reboot == '1' }}"
|
||||
upgrade_needs_reboot: "{{ _firmware_status.json.upgrade_needs_reboot == '1' }}"
|
||||
firmware_up_to_date: "{{ _firmware_status.json.status_msg == 'There are no updates available on the selected mirror.' }}"
|
||||
needs_reboot: "{{ (_firmware_status.json.upgrade_needs_reboot == '1') if _firmware_status.json.status == 'upgrade' else (_firmware_status.json.needs_reboot == '1') }}"
|
||||
total_vips: "{{ _vip_status.json.rowCount }}"
|
||||
mismatched_vips: "{{ _vip_status.json.rows | rejectattr('status', 'equalto', main_role) | list | length }}"
|
||||
in_maintenance: "{{ _vip_status.json.carp.maintenancemode }}"
|
||||
|
||||
- name: Resolve update-vs-upgrade specifics
|
||||
ansible.builtin.set_fact:
|
||||
needs_reboot: "{{ upgrade_needs_reboot if firmware_status == 'upgrade' else update_needs_reboot }}"
|
||||
firmware_target_kind: "{{ 'series' if firmware_status == 'upgrade' else 'version' }}"
|
||||
firmware_target_value: "{{ firmware_upgrade_version if firmware_status == 'upgrade' else firmware_update_version }}"
|
||||
|
||||
- name: Skip backup {{ firmware_action }}
|
||||
- name: Backup already updated
|
||||
ansible.builtin.set_fact:
|
||||
skip_update: true
|
||||
firmware_status: "skipped"
|
||||
delegate_to: "{{ groups['opnsense_backup'][0] }}"
|
||||
delegate_facts: true
|
||||
run_once: true
|
||||
when: >-
|
||||
(hostvars[groups['opnsense_backup'][0]]
|
||||
['firmware_current_version'
|
||||
if hostvars[groups['opnsense_master'][0]].firmware_target_kind == 'version'
|
||||
else 'firmware_product_series'])
|
||||
== hostvars[groups['opnsense_master'][0]].firmware_target_value
|
||||
when: (hostvars[groups['opnsense_backup'][0]].firmware_current_version if hostvars[groups['opnsense_master'][0]].firmware_target_kind == 'version' else 'firmware_product_series']) == hostvars[groups['opnsense_master'][0]].firmware_target_value or
|
||||
|
||||
- name: Skip node {{ firmware_action }}
|
||||
ansible.builtin.set_fact:
|
||||
skip_update: true
|
||||
firmware_status: "skipped"
|
||||
when: firmware_up_to_date or
|
||||
firmware_action != firmware_status
|
||||
|
||||
- name: "Assert"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- firmware_action == firmware_status or skip_update | default(false)
|
||||
- not in_maintenance
|
||||
- mismatched_vips == 0
|
||||
- total_vips > 0
|
||||
@@ -106,26 +107,19 @@
|
||||
force_basic_auth: true
|
||||
body: |
|
||||
Current version: {{ firmware_current_version }}
|
||||
{% if firmware_action != firmware_status %}
|
||||
{% if firmware_status == "upgrade" %}
|
||||
Upgrade to {{ firmware_upgrade_version }} available, but no upgrade requested.
|
||||
{% if firmware_upgrade_message != "" %}
|
||||
Upgrade message:
|
||||
{{ firmware_upgrade_message }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
No updates available on the cluster.
|
||||
{% endif %}
|
||||
{% elif in_maintenance %}
|
||||
{% if in_maintenance %}
|
||||
The node {{ inventory_hostname }} is in CARP maintenance mode.
|
||||
{% elif mismatched_vips > 0 %}
|
||||
Some VIP are not {{ main_role }} on {{ ansible_host }}.
|
||||
{% else %}
|
||||
{% elif total_vips == 0 %}
|
||||
No VIPs are managed.
|
||||
{% else %}
|
||||
An error occured during the {{ firmware_action }}.
|
||||
{% endif %}
|
||||
headers:
|
||||
Title: "OPNsense {{ firmware_action }} report"
|
||||
Priority: "default"
|
||||
Tags: "x"
|
||||
run_once: true
|
||||
when: ntfy_url is defined
|
||||
|
||||
@@ -193,7 +187,7 @@
|
||||
- name: Check firmware version
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/core/firmware/status"
|
||||
method: POST
|
||||
method: GET
|
||||
user: "{{ opnsense_api_key }}"
|
||||
password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
@@ -256,7 +250,8 @@
|
||||
|
||||
tasks:
|
||||
|
||||
- block:
|
||||
- when: not skip_update | default(false)
|
||||
block:
|
||||
|
||||
- name: Take Proxmox VM snapshot
|
||||
community.proxmox.proxmox_snap:
|
||||
@@ -320,7 +315,7 @@
|
||||
- name: Check firmware version
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ opnsense_host }}/api/core/firmware/status"
|
||||
method: POST
|
||||
method: GET
|
||||
user: "{{ opnsense_api_key }}"
|
||||
password: "{{ opnsense_api_secret }}"
|
||||
force_basic_auth: true
|
||||
@@ -383,7 +378,7 @@
|
||||
msg: "Update aborted"
|
||||
|
||||
|
||||
- name: "Phase 4 | Notify on succes"
|
||||
- name: "Phase 4 | Notification"
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
|
||||
Reference in New Issue
Block a user