Update ansible/update.yml

This commit is contained in:
2026-08-11 22:18:24 +02:00
parent 22d366dce0
commit 17d2678724

View File

@@ -1,16 +1,45 @@
--- ---
- name: Aktualizacja systemów i sprawdzenie wymaganych restartów - name: Aktualizacja systemów i sprawdzenie wymaganych restartów
hosts: all hosts: all
gather_facts: true gather_facts: false
ignore_unreachable: true
tasks: tasks:
# ==========================================
# BEZBŁĘDNE SPRAWDZENIE CZY HOST JEST WŁĄCZONY
# ==========================================
- name: Próba połączenia SSH (check online status)
block:
- name: Sprawdzenie portu SSH
ansible.builtin.wait_for:
host: "{{ ansible_host | default(inventory_hostname) }}"
port: "{{ ansible_port | default(22) }}"
state: started
delay: 0
timeout: 3
delegate_to: localhost
- name: Ustawienie statusu ONLINE
ansible.builtin.set_fact:
host_is_online: true
rescue:
- name: Ustawienie statusu OFFLINE (bez generowania błędu)
ansible.builtin.set_fact:
host_is_online: false
# ==========================================
# ZBIERANIE FAKTÓW (tylko dla aktywnych hostów)
# ==========================================
- name: Zbieranie faktów systemowych
ansible.builtin.setup:
when: host_is_online
# ========================================== # ==========================================
# DEBIAN / UBUNTU # DEBIAN / UBUNTU
# ========================================== # ==========================================
- name: Aktualizacja pakietów (Debian/Ubuntu) - name: Aktualizacja pakietów (Debian/Ubuntu)
when: when:
- ansible_os_family == 'Debian' - host_is_online
- ansible_os_family | default('') == 'Debian'
- not (skip_apt | default(false)) - not (skip_apt | default(false))
block: block:
- name: Aktualizacja pamięci podręcznej i podniesienie pakietów - name: Aktualizacja pamięci podręcznej i podniesienie pakietów
@@ -34,7 +63,8 @@
# ========================================== # ==========================================
- name: Aktualizacja pakietów (Alpine Linux) - name: Aktualizacja pakietów (Alpine Linux)
when: when:
- ansible_os_family == 'Alpine' - host_is_online
- ansible_os_family | default('') == 'Alpine'
- not (skip_apt | default(false)) - not (skip_apt | default(false))
block: block:
- name: Aktualizacja pamięci podręcznej i pakietów (apk) - name: Aktualizacja pamięci podręcznej i pakietów (apk)
@@ -65,6 +95,6 @@
- name: Informacja o stanie po aktualizacji - name: Informacja o stanie po aktualizacji
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "Host: {{ inventory_hostname }} ({{ ansible_distribution | default('N/A') }} {{ ansible_distribution_version | default('') }})" - "Host: {{ inventory_hostname }} ({{ ansible_distribution | default('Nieokreślony') }})"
- "Status: {{ '⏭️ POMINIĘTO (skip_apt = true)' if (skip_apt | default(false)) else '✅ ZAKOŃCZONO SUCCESS' }}" - "Status: {{ '🔴 NIEOSIĄGALNY / WYŁĄCZONY' if not host_is_online else ('⏭️ POMINIĘTO (skip_apt)' if (skip_apt | default(false)) else '✅ ZAKOŃCZONO SUCCESS') }}"
- "Status restartu: {{ '⚠️ WYMAGANY RESTART!' if (reboot_needed | default(false)) else '✅ Brak potrzeby restartu' }}" - "Status restartu: {{ '⚠️ WYMAGANY RESTART!' if (reboot_needed | default(false)) else '✅ Brak potrzeby restartu' }}"