os-upgrade-automation/playbook/roles/preflight_check/tasks/main.yml

132 lines
4.0 KiB
YAML

---
- name: "Prüfe, ob aktueller Zeitpunkt im Maintenance-Window liegt"
ansible.builtin.set_fact:
now: "{{ lookup('pipe', 'date +%H:%M') }}"
window_start: "{{ maintenance_window_start }}"
window_end: "{{ maintenance_window_end }}"
changed_when: false
tags: preflight
- name: "Maintenance-Window-Check (Abbruch, wenn außerhalb)"
ansible.builtin.fail:
msg: "Aktuelle Zeit {{ now }} liegt außerhalb des Maintenance-Windows ({{ window_start }} - {{ window_end }}). Upgrade wird abgebrochen!"
when: >-
(
(window_start < window_end and (now < window_start or now > window_end))
or
(window_start > window_end and (now < window_start and now > window_end))
)
tags: preflight
- name: "Prüfe freien Speicherplatz auf / (mind. 5GB empfohlen)"
ansible.builtin.stat:
path: /
register: root_stat
tags: preflight
- name: Warnung bei zu wenig Speicherplatz
ansible.builtin.assert:
that:
- root_stat.stat.avail_bytes > 5368709120
fail_msg: "Wenig freier Speicherplatz auf /: {{ root_stat.stat.avail_bytes | human_readable }} (mind. 5GB empfohlen)"
success_msg: "Genügend Speicherplatz auf /: {{ root_stat.stat.avail_bytes | human_readable }}"
tags: preflight
- name: Prüfe Erreichbarkeit von SUSE Manager
ansible.builtin.uri:
url: "{{ suma_api_url }}"
method: GET
validate_certs: no
timeout: 10
register: suma_reachable
ignore_errors: true
retries: 3
delay: 5
tags: preflight
- name: Warnung, wenn SUSE Manager nicht erreichbar
ansible.builtin.assert:
that:
- suma_reachable.status is defined and suma_reachable.status == 200
fail_msg: "SUSE Manager API nicht erreichbar!"
success_msg: "SUSE Manager API erreichbar."
tags: preflight
- name: Prüfe, ob VMware-Snapshot-Modul verfügbar ist
ansible.builtin.shell: "python3 -c 'import pyVmomi'"
register: pyvmomi_check
ignore_errors: true
changed_when: false
tags: preflight
- name: Warnung, wenn pyVmomi nicht installiert ist
ansible.builtin.assert:
that:
- pyvmomi_check.rc == 0
fail_msg: "pyVmomi (VMware-Modul) nicht installiert!"
success_msg: "pyVmomi ist installiert."
tags: preflight
- name: Prüfe, ob aktueller SUSE Manager Channel synchronisiert ist
ansible.builtin.uri:
url: "{{ suma_api_url }}"
method: POST
body_format: json
headers:
Content-Type: application/json
body: |
{
"method": "auth.login",
"params": ["{{ suma_api_user }}", "{{ suma_api_pass }}"],
"id": 1
}
validate_certs: no
timeout: 20
register: suma_api_login
ignore_errors: true
retries: 3
delay: 10
async: 60
poll: 0
tags: preflight
- name: Hole Channel-Details für Ziel-CLM-Version
ansible.builtin.uri:
url: "{{ suma_api_url }}"
method: POST
body_format: json
headers:
Content-Type: application/json
body: |
{
"method": "channel.software.getDetails",
"params": ["{{ suma_api_login.json.result }}", "{{ target_clm_version }}"],
"id": 2
}
validate_certs: no
timeout: 20
register: suma_channel_details
ignore_errors: true
retries: 3
delay: 10
async: 60
poll: 0
tags: preflight
- name: Prüfe Channel-Sync-Status
ansible.builtin.assert:
that:
- suma_channel_details.json.result.last_sync is defined
fail_msg: "Channel {{ target_clm_version }} ist nicht synchronisiert!"
success_msg: "Channel {{ target_clm_version }} wurde zuletzt synchronisiert am {{ suma_channel_details.json.result.last_sync }}."
tags: preflight
- name: Slack-Benachrichtigung bei kritischen Fehlern (Beispiel)
community.general.slack:
token: "{{ slack_token | default('xoxb-...') }}"
msg: "[CRITICAL] Fehler beim Preflight-Check auf {{ inventory_hostname }}: {{ ansible_failed_result.msg | default('Unbekannter Fehler') }}"
channel: "#linux-admins"
when: slack_enabled | default(false) and (ansible_failed_result is defined and ansible_failed_result is not none)
ignore_errors: true
tags: preflight