Update ansible/clear.yml

This commit is contained in:
2026-08-11 22:38:12 +02:00
parent f0316c606a
commit 02808dc22f

View File

@@ -6,10 +6,17 @@
tasks: 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: 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 - name: Sprawdzenie portu SSH
ansible.builtin.wait_for: ansible.builtin.wait_for:
host: "{{ ansible_host | default(inventory_hostname) }}" host: "{{ ansible_host | default(inventory_hostname) }}"
@@ -32,15 +39,21 @@
# ========================================== # ==========================================
- name: Zbieranie faktów systemowych - name: Zbieranie faktów systemowych
ansible.builtin.setup: 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 # CZYSZCZENIE SYSTEMOWE
# ========================================== # ==========================================
- name: Czyszczenie Apt (Debian/Ubuntu) - name: Czyszczenie Apt (Debian/Ubuntu)
when: when:
- host_is_online - not (skip | default(false))
- host_is_online | default(false)
- ansible_os_family | default('') == 'Debian' - ansible_os_family | default('') == 'Debian'
ignore_unreachable: true
block: block:
- name: Usuwanie niepotrzebnych pakietów (autoremove) - name: Usuwanie niepotrzebnych pakietów (autoremove)
ansible.builtin.apt: ansible.builtin.apt:
@@ -54,8 +67,10 @@
- name: Czyszczenie Apk (Alpine) - name: Czyszczenie Apk (Alpine)
when: when:
- host_is_online - not (skip | default(false))
- host_is_online | default(false)
- ansible_os_family | default('') == 'Alpine' - ansible_os_family | default('') == 'Alpine'
ignore_unreachable: true
block: block:
- name: Czyszczenie cache apk - name: Czyszczenie cache apk
ansible.builtin.command: apk cache clean ansible.builtin.command: apk cache clean
@@ -69,13 +84,18 @@
register: docker_check register: docker_check
failed_when: false failed_when: false
changed_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 - name: Czyszczenie nieużywanych zasobów Dockera
when: when:
- host_is_online - not (skip | default(false))
- host_is_online | default(false)
- docker_check.rc is defined - docker_check.rc is defined
- docker_check.rc == 0 - docker_check.rc == 0
ignore_unreachable: true
block: block:
- name: Docker system prune (obrazy, sieci, kontenery, wolumeny) - name: Docker system prune (obrazy, sieci, kontenery, wolumeny)
ansible.builtin.command: docker system prune -af --volumes ansible.builtin.command: docker system prune -af --volumes
@@ -93,4 +113,4 @@
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "Host: {{ inventory_hostname }}" - "Host: {{ inventory_hostname }}"
- "Status: {{ '🔴 OFFLINE' if not host_is_online else '✅ WYKONANO KONSERWACJĘ' }}" - "Status: {{ '⏭️ POMINIĘTO (skip: true)' if (skip | default(false)) else ('🔴 OFFLINE / UNREACHABLE' if not (host_is_online | default(false)) else '✅ WYKONANO KONSERWACJĘ') }}"