Update ansible/clear.yml

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

View File

@@ -3,29 +3,32 @@
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)
ansible.builtin.wait_for: block:
host: "{{ ansible_host | default(inventory_hostname) }}" - name: Sprawdzenie portu SSH
port: "{{ ansible_port | default(22) }}" ansible.builtin.wait_for:
state: started host: "{{ ansible_host | default(inventory_hostname) }}"
delay: 0 port: "{{ ansible_port | default(22) }}"
timeout: 3 state: started
delegate_to: localhost delay: 0
register: ssh_check timeout: 3
ignore_errors: true delegate_to: localhost
- 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)