diff --git a/ansible/update.yml b/ansible/update.yml index 6acb889..d6b42ab 100644 --- a/ansible/update.yml +++ b/ansible/update.yml @@ -1,16 +1,45 @@ --- - name: Aktualizacja systemów i sprawdzenie wymaganych restartów hosts: all - gather_facts: true - ignore_unreachable: true + gather_facts: false 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 # ========================================== - name: Aktualizacja pakietów (Debian/Ubuntu) when: - - ansible_os_family == 'Debian' + - host_is_online + - ansible_os_family | default('') == 'Debian' - not (skip_apt | default(false)) block: - name: Aktualizacja pamięci podręcznej i podniesienie pakietów @@ -34,7 +63,8 @@ # ========================================== - name: Aktualizacja pakietów (Alpine Linux) when: - - ansible_os_family == 'Alpine' + - host_is_online + - ansible_os_family | default('') == 'Alpine' - not (skip_apt | default(false)) block: - name: Aktualizacja pamięci podręcznej i pakietów (apk) @@ -65,6 +95,6 @@ - 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' }}" + - "Host: {{ inventory_hostname }} ({{ ansible_distribution | default('Nieokreślony') }})" + - "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' }}" \ No newline at end of file