Update ansible/clear.yml

This commit is contained in:
2026-08-11 22:18:35 +02:00
parent 17d2678724
commit 11697fe3ce

View File

@@ -3,13 +3,14 @@
hosts: all hosts: all
become: true become: true
gather_facts: false gather_facts: false
ignore_errors: true
tasks: tasks:
# ========================================== # ==========================================
# SPRAWDZENIE CZY HOST JEST WŁĄCZONY (SSH) # BEZBŁĘDNE SPRAWDZENIE CZY HOST JEST WŁĄCZONY
# ========================================== # ==========================================
- name: Sprawdzenie dostępności portu SSH - name: Próba połączenia SSH (check online status)
block:
- name: Sprawdzenie portu SSH
ansible.builtin.wait_for: ansible.builtin.wait_for:
host: "{{ ansible_host | default(inventory_hostname) }}" host: "{{ ansible_host | default(inventory_hostname) }}"
port: "{{ ansible_port | default(22) }}" port: "{{ ansible_port | default(22) }}"
@@ -17,15 +18,17 @@
delay: 0 delay: 0
timeout: 3 timeout: 3
delegate_to: localhost delegate_to: localhost
register: ssh_check
ignore_errors: true
- name: Oznaczenie statusu hosta - name: Ustawienie statusu ONLINE
ansible.builtin.set_fact: ansible.builtin.set_fact:
host_is_online: "{{ not (ssh_check.failed | default(false)) }}" 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 online) # ZBIERANIE FAKTÓW (tylko dla aktywnych hostów)
# ========================================== # ==========================================
- name: Zbieranie faktów systemowych - name: Zbieranie faktów systemowych
ansible.builtin.setup: ansible.builtin.setup:
@@ -71,6 +74,7 @@
- name: Czyszczenie nieużywanych zasobów Dockera - name: Czyszczenie nieużywanych zasobów Dockera
when: when:
- host_is_online - host_is_online
- docker_check.rc is defined
- docker_check.rc == 0 - docker_check.rc == 0
block: block:
- name: Docker system prune (obrazy, sieci, kontenery, wolumeny) - name: Docker system prune (obrazy, sieci, kontenery, wolumeny)