69 lines
2.7 KiB
YAML
69 lines
2.7 KiB
YAML
---
|
|
- name: Aktualizacja systemów i sprawdzenie wymaganych restartów
|
|
hosts: all
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
# ==========================================
|
|
# DEBIAN / UBUNTU
|
|
# ==========================================
|
|
- name: Aktualizacja pakietów (Debian/Ubuntu)
|
|
when:
|
|
- ansible_os_family == 'Debian'
|
|
- not (skip_apt | default(false))
|
|
block:
|
|
- name: Aktualizacja pamięci podręcznej i podniesienie pakietów
|
|
ansible.builtin.apt:
|
|
update_cache: true
|
|
upgrade: dist
|
|
autoremove: true
|
|
autoclean: true
|
|
|
|
- name: Sprawdzenie czy wymagany jest restart (Debian/Ubuntu)
|
|
ansible.builtin.stat:
|
|
path: /var/run/reboot-required
|
|
register: debian_reboot_file
|
|
|
|
- name: Zapisanie informacji o restarcie (Debian/Ubuntu)
|
|
ansible.builtin.set_fact:
|
|
reboot_needed: "{{ debian_reboot_file.stat.exists }}"
|
|
|
|
# ==========================================
|
|
# ALPINE LINUX
|
|
# ==========================================
|
|
- name: Aktualizacja pakietów (Alpine Linux)
|
|
when:
|
|
- ansible_os_family == 'Alpine'
|
|
- not (skip_apt | default(false))
|
|
block:
|
|
- name: Aktualizacja pamięci podręcznej i pakietów (apk)
|
|
community.general.apk:
|
|
update_cache: true
|
|
upgrade: true
|
|
|
|
- name: Sprawdzenie czy jądro systemu wymaga restartu (Alpine)
|
|
ansible.builtin.shell:
|
|
cmd: |
|
|
running_kernel=$(uname -r)
|
|
installed_kernel=$(ls -1 /boot/vmlinuz-* 2>/dev/null | tail -n1 | sed 's/.*vmlinuz-//')
|
|
if [ -n "$installed_kernel" ] && [ "$running_kernel" != "$installed_kernel" ]; then
|
|
echo "reboot_required"
|
|
fi
|
|
executable: /bin/sh
|
|
register: alpine_kernel_check
|
|
changed_when: false
|
|
ignore_errors: true
|
|
|
|
- name: Zapisanie informacji o restarcie (Alpine)
|
|
ansible.builtin.set_fact:
|
|
reboot_needed: "{{ 'reboot_required' in alpine_kernel_check.stdout }}"
|
|
|
|
# ==========================================
|
|
# PODSUMOWANIE
|
|
# ==========================================
|
|
- name: Informacja o stanie po aktualizacji
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "Host: {{ inventory_hostname }} ({{ ansible_distribution | default('N/A') }} {{ ansible_distribution_version | default('') }})"
|
|
- "Status: {{ '⏭️ POMINIĘTO (skip_apt = true)' if (skip_apt | default(false)) else '✅ ZAKOŃCZONO SUCCESS' }}"
|
|
- "Status restartu: {{ '⚠️ WYMAGANY RESTART!' if (reboot_needed | default(false)) else '✅ Brak potrzeby restartu' }}" |