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