From 02808dc22ff10adc9702f7ef6f3920ffea569580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=BBbikowski?= Date: Tue, 11 Aug 2026 22:38:12 +0200 Subject: [PATCH] Update ansible/clear.yml --- ansible/clear.yml | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/ansible/clear.yml b/ansible/clear.yml index 050f1b2..f4503e1 100644 --- a/ansible/clear.yml +++ b/ansible/clear.yml @@ -6,10 +6,17 @@ tasks: # ========================================== - # BEZBŁĘDNE SPRAWDZENIE CZY HOST JEST WŁĄCZONY + # SPRAWDZENIE DOSTĘPNOŚCI (SKIP + PING + SSH) # ========================================== - - name: Próba połączenia SSH (check online status) + - name: Weryfikacja dostępności hosta + when: not (skip | default(false)) block: + - name: Sprawdzenie odpowiedzi ICMP Ping + ansible.builtin.command: + cmd: "ping -c 1 -W 2 {{ ansible_host | default(inventory_hostname) }}" + delegate_to: localhost + changed_when: false + - name: Sprawdzenie portu SSH ansible.builtin.wait_for: host: "{{ ansible_host | default(inventory_hostname) }}" @@ -32,15 +39,21 @@ # ========================================== - name: Zbieranie faktów systemowych ansible.builtin.setup: - when: host_is_online + when: + - not (skip | default(false)) + - host_is_online | default(false) + ignore_unreachable: true + ignore_errors: true # ========================================== # CZYSZCZENIE SYSTEMOWE # ========================================== - name: Czyszczenie Apt (Debian/Ubuntu) when: - - host_is_online + - not (skip | default(false)) + - host_is_online | default(false) - ansible_os_family | default('') == 'Debian' + ignore_unreachable: true block: - name: Usuwanie niepotrzebnych pakietów (autoremove) ansible.builtin.apt: @@ -54,8 +67,10 @@ - name: Czyszczenie Apk (Alpine) when: - - host_is_online + - not (skip | default(false)) + - host_is_online | default(false) - ansible_os_family | default('') == 'Alpine' + ignore_unreachable: true block: - name: Czyszczenie cache apk ansible.builtin.command: apk cache clean @@ -69,13 +84,18 @@ register: docker_check failed_when: false changed_when: false - when: host_is_online + ignore_unreachable: true + when: + - not (skip | default(false)) + - host_is_online | default(false) - name: Czyszczenie nieużywanych zasobów Dockera when: - - host_is_online + - not (skip | default(false)) + - host_is_online | default(false) - docker_check.rc is defined - docker_check.rc == 0 + ignore_unreachable: true block: - name: Docker system prune (obrazy, sieci, kontenery, wolumeny) ansible.builtin.command: docker system prune -af --volumes @@ -93,4 +113,4 @@ ansible.builtin.debug: msg: - "Host: {{ inventory_hostname }}" - - "Status: {{ '🔴 OFFLINE' if not host_is_online else '✅ WYKONANO KONSERWACJĘ' }}" \ No newline at end of file + - "Status: {{ '⏭️ POMINIĘTO (skip: true)' if (skip | default(false)) else ('🔴 OFFLINE / UNREACHABLE' if not (host_is_online | default(false)) else '✅ WYKONANO KONSERWACJĘ') }}" \ No newline at end of file