Update ansible/clear.yml
This commit is contained in:
@@ -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Ę' }}"
|
||||
- "Status: {{ '⏭️ POMINIĘTO (skip: true)' if (skip | default(false)) else ('🔴 OFFLINE / UNREACHABLE' if not (host_is_online | default(false)) else '✅ WYKONANO KONSERWACJĘ') }}"
|
||||
Reference in New Issue
Block a user