Add ansible/update.yml
This commit is contained in:
66
ansible/update.yml
Normal file
66
ansible/update.yml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
---
|
||||||
|
- 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'
|
||||||
|
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'
|
||||||
|
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: |
|
||||||
|
set -o pipefail
|
||||||
|
[ -f /var/run/openrc/started/bootmisc ] || exit 0
|
||||||
|
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 }} {{ ansible_distribution_version }})"
|
||||||
|
- "Aktualizacja: ZAKOŃCZONA SUCCESS"
|
||||||
|
- "Status restartu: {{ '⚠️ WYMAGANY RESTART!' if reboot_needed | default(false) else '✅ Brak potrzeby restartu' }}"
|
||||||
Reference in New Issue
Block a user