add community-scripts update playbook, fail on real errors
- add update_scripts.yml: runs `update` on hosts with scripts: true (PHS_SILENT=1), skipping skip: true and scripts_exclude: true - exclude the semaphore host from it via scripts_exclude: true - clear.yml: prune Docker only on hosts with docker: true - all playbooks: offline hosts are not an error, but a reachable host that fails a task now fails the job (drop ignore_errors / ignore_unreachable) - update.yml: do not gather facts from skip: true hosts - beszel_agent.yml: always remove the installer from /tmp - ping_check.yml: fail when the SSH port is open but login fails - security.yml: fix invalid set_fact YAML Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8dccc305a3
commit
10bcc99de8
7 files changed
+113
-37
No files matched your search
@@ -50,7 +50,6 @@
|
||||
when:
|
||||
- not (skip | default(false))
|
||||
- host_is_online | default(false)
|
||||
ignore_unreachable: true
|
||||
block:
|
||||
- name: Pobranie skryptu instalacyjnego Beszel
|
||||
ansible.builtin.get_url:
|
||||
@@ -68,8 +67,7 @@
|
||||
--auto-update
|
||||
register: beszel_install
|
||||
changed_when: "'Installation complete' in beszel_install.stdout or beszel_install.rc == 0"
|
||||
ignore_errors: true
|
||||
|
||||
always:
|
||||
- name: Usunięcie pliku instalacyjnego z /tmp
|
||||
ansible.builtin.file:
|
||||
path: "/tmp/install-agent.sh"
|
||||
|
||||
+2
-18
@@ -42,8 +42,6 @@
|
||||
when:
|
||||
- not (skip | default(false))
|
||||
- host_is_online | default(false)
|
||||
ignore_unreachable: true
|
||||
ignore_errors: true
|
||||
|
||||
# ==========================================
|
||||
# CZYSZCZENIE SYSTEMOWE
|
||||
@@ -53,7 +51,6 @@
|
||||
- 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:
|
||||
@@ -70,7 +67,6 @@
|
||||
- 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
|
||||
@@ -79,23 +75,11 @@
|
||||
# ==========================================
|
||||
# CZYSZCZENIE DOCKERA
|
||||
# ==========================================
|
||||
- name: Sprawdzenie czy Docker jest zainstalowany
|
||||
ansible.builtin.command: which docker
|
||||
register: docker_check
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
ignore_unreachable: true
|
||||
when:
|
||||
- not (skip | default(false))
|
||||
- host_is_online | default(false)
|
||||
|
||||
- name: Czyszczenie nieużywanych zasobów Dockera
|
||||
when:
|
||||
when:
|
||||
- not (skip | default(false))
|
||||
- docker | default(false) | bool
|
||||
- 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
|
||||
|
||||
+17
-7
@@ -52,13 +52,13 @@
|
||||
block:
|
||||
- name: Próba zalogowania i wykonania modułu ping
|
||||
ansible.builtin.ping:
|
||||
- name: Ustaw wynik logowania jako SUKCES
|
||||
register: ssh_login_result
|
||||
ignore_unreachable: true
|
||||
ignore_errors: true
|
||||
- name: Ustaw wynik logowania
|
||||
ansible.builtin.set_fact:
|
||||
ssh_login_status: "SUKCES"
|
||||
rescue:
|
||||
- name: Ustaw wynik logowania jako BŁĄD LOGOWANIA
|
||||
ansible.builtin.set_fact:
|
||||
ssh_login_status: "BŁĄD LOGOWANIA / BRAK UPRAWNIEŃ"
|
||||
ssh_login_ok: "{{ ssh_login_result.ping | default('') == 'pong' }}"
|
||||
ssh_login_status: "{{ 'SUKCES' if (ssh_login_result.ping | default('') == 'pong') else 'BŁĄD LOGOWANIA / BRAK UPRAWNIEŃ' }}"
|
||||
|
||||
# ==========================================
|
||||
# 4. PODSUMOWANIE DLA DANEGO HOSTA
|
||||
@@ -69,4 +69,14 @@
|
||||
- "Host: {{ inventory_hostname }}"
|
||||
- "PING (ICMP): {{ icmp_status }}"
|
||||
- "Port SSH (22): {{ ssh_port_status }}"
|
||||
- "Logowanie SSH: {{ ssh_login_status | default('POMINIĘTO (Port zamknięty)') }}"
|
||||
- "Logowanie SSH: {{ ssh_login_status | default('POMINIĘTO (Port zamknięty)') }}"
|
||||
|
||||
# ==========================================
|
||||
# 5. BŁĄD, GDY HOST ODPOWIADA, ALE LOGOWANIE SIĘ NIE UDAŁO
|
||||
# ==========================================
|
||||
- name: Błąd logowania SSH na dostępnym hoście
|
||||
ansible.builtin.fail:
|
||||
msg: "Port SSH jest otwarty, ale logowanie się nie powiodło"
|
||||
when:
|
||||
- ssh_port_open
|
||||
- not (ssh_login_ok | default(false))
|
||||
+3
-6
@@ -37,9 +37,9 @@
|
||||
# ==========================================
|
||||
- name: Zbieranie faktów systemowych
|
||||
ansible.builtin.setup:
|
||||
when: host_is_online | default(false)
|
||||
ignore_unreachable: true
|
||||
ignore_errors: true
|
||||
when:
|
||||
- host_is_online | default(false)
|
||||
- not (skip | default(false))
|
||||
|
||||
# ==========================================
|
||||
# DEBIAN / UBUNTU
|
||||
@@ -49,7 +49,6 @@
|
||||
- host_is_online | default(false)
|
||||
- ansible_os_family | default('') == 'Debian'
|
||||
- not (skip | default(false))
|
||||
ignore_unreachable: true
|
||||
block:
|
||||
- name: Aktualizacja pamięci podręcznej i podniesienie pakietów
|
||||
ansible.builtin.apt:
|
||||
@@ -75,7 +74,6 @@
|
||||
- host_is_online | default(false)
|
||||
- ansible_os_family | default('') == 'Alpine'
|
||||
- not (skip | default(false))
|
||||
ignore_unreachable: true
|
||||
block:
|
||||
- name: Aktualizacja pamięci podręcznej i pakietów (apk)
|
||||
community.general.apk:
|
||||
@@ -93,7 +91,6 @@
|
||||
executable: /bin/sh
|
||||
register: alpine_kernel_check
|
||||
changed_when: false
|
||||
ignore_errors: true
|
||||
|
||||
- name: Zapisanie informacji o restarcie (Alpine)
|
||||
ansible.builtin.set_fact:
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
---
|
||||
- name: Aktualizacja kontenerów LXC z community-scripts (komenda update)
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
|
||||
vars:
|
||||
# scripts_exclude: true -> host ma scripts: true, ale nie jest aktualizowany tym playbookiem
|
||||
scripts_enabled: "{{ (scripts | default(false) | bool) and not (scripts_exclude | default(false) | bool) and not (skip | default(false) | bool) }}"
|
||||
|
||||
tasks:
|
||||
# ==========================================
|
||||
# SPRAWDZENIE DOSTĘPNOŚCI (SKIP + SCRIPTS + PING + SSH)
|
||||
# ==========================================
|
||||
- name: Weryfikacja dostępności hosta
|
||||
when: scripts_enabled
|
||||
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) }}"
|
||||
port: "{{ ansible_port | default(22) }}"
|
||||
state: started
|
||||
delay: 0
|
||||
timeout: 3
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Ustawienie statusu ONLINE
|
||||
ansible.builtin.set_fact:
|
||||
host_is_online: true
|
||||
rescue:
|
||||
- name: Ustawienie statusu OFFLINE (bez generowania błędu)
|
||||
ansible.builtin.set_fact:
|
||||
host_is_online: false
|
||||
|
||||
# ==========================================
|
||||
# AKTUALIZACJA (community-scripts)
|
||||
# ==========================================
|
||||
- name: Aktualizacja kontenera komendą update
|
||||
when:
|
||||
- scripts_enabled
|
||||
- host_is_online | default(false)
|
||||
block:
|
||||
# PHS_SILENT=1 pomija menu whiptail (misc/build.func -> start())
|
||||
- name: Uruchomienie komendy update (tryb cichy, bez menu)
|
||||
ansible.builtin.command: update
|
||||
environment:
|
||||
PHS_SILENT: "1"
|
||||
TERM: xterm
|
||||
register: scripts_update
|
||||
|
||||
- name: Wyświetlenie wyniku aktualizacji
|
||||
ansible.builtin.debug:
|
||||
var: scripts_update.stdout_lines
|
||||
|
||||
# ==========================================
|
||||
# PODSUMOWANIE
|
||||
# ==========================================
|
||||
- name: Informacja o stanie po aktualizacji
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "Host: {{ inventory_hostname }}"
|
||||
- "Status: {{ '⏭️ POMINIĘTO (skip: true)' if (skip | default(false)) else ('⏭️ POMINIĘTO (brak scripts: true)' if not (scripts | default(false) | bool) else ('⏭️ POMINIĘTO (scripts_exclude: true)' if (scripts_exclude | default(false) | bool) else ('🔴 OFFLINE / UNREACHABLE' if not (host_is_online | default(false)) else '✅ ZAKTUALIZOWANO'))) }}"
|
||||
@@ -21,8 +21,10 @@ all:
|
||||
traefik.nni.kzbikowski.pl:
|
||||
pve_id: 100
|
||||
docker: true
|
||||
scripts: true
|
||||
pmg.nni.kzbikowski.pl:
|
||||
pve_id: 101
|
||||
scripts: true
|
||||
mail.nni.kzbikowski.pl:
|
||||
pve_id: 103
|
||||
docker: true
|
||||
@@ -31,29 +33,39 @@ all:
|
||||
arr.nni.kzbikowski.pl:
|
||||
pve_id: 105
|
||||
docker: true
|
||||
scripts: true
|
||||
cloud.nni.kzbikowski.pl:
|
||||
pve_id: 106
|
||||
docker: true
|
||||
scripts: true
|
||||
auth.nni.kzbikowski.pl:
|
||||
pve_id: 107
|
||||
docker: true
|
||||
scripts: true
|
||||
photos.nni.kzbikowski.pl:
|
||||
pve_id: 108
|
||||
docker: true
|
||||
scripts: true
|
||||
vpn.nni.kzbikowski.pl:
|
||||
pve_id: 110
|
||||
docker: true
|
||||
scripts: true
|
||||
ns1.dns:
|
||||
pve_id: 111
|
||||
scripts: true
|
||||
ns2.dns:
|
||||
pve_id: 112
|
||||
scripts: true
|
||||
atak.nni.kzbikowski.pl:
|
||||
pve_id: 113
|
||||
scripts: true
|
||||
ollama.nni.kzbikowski.pl:
|
||||
pve_id: 114
|
||||
scripts: true
|
||||
pelican.nni.kzbikowski.pl:
|
||||
pve_id: 116
|
||||
docker: true
|
||||
scripts: true
|
||||
truenas.nni.kzbikowski.pl:
|
||||
pve_id: 901
|
||||
skip: true
|
||||
@@ -91,12 +103,17 @@ all:
|
||||
hosts:
|
||||
ns4.dns:
|
||||
pve_id: 100
|
||||
scripts: true
|
||||
pdm.neo.kzbikowski.pl:
|
||||
pve_id: 103
|
||||
scripts: true
|
||||
beszel.neo.kzbikowski.pl:
|
||||
pve_id: 105
|
||||
scripts: true
|
||||
semaphore.neo.kzbikowski.pl:
|
||||
pve_id: 106
|
||||
scripts: true
|
||||
scripts_exclude: true
|
||||
|
||||
# ==========================================
|
||||
# ZMIENNE GLOBALNE DLA WSZYSTKICH HOSTÓW
|
||||
|
||||
@@ -14,15 +14,18 @@
|
||||
port: "{{ ansible_port | default(22) }}"
|
||||
timeout: 3
|
||||
delegate_to: localhost
|
||||
- ansible.builtin.set_fact: host_is_online: true
|
||||
- name: Ustawienie statusu ONLINE
|
||||
ansible.builtin.set_fact:
|
||||
host_is_online: true
|
||||
rescue:
|
||||
- ansible.builtin.set_fact: host_is_online: false
|
||||
- name: Ustawienie statusu OFFLINE (bez generowania błędu)
|
||||
ansible.builtin.set_fact:
|
||||
host_is_online: false
|
||||
|
||||
- name: Zabezpieczanie SSH
|
||||
when:
|
||||
- not (skip | default(false))
|
||||
- host_is_online | default(false)
|
||||
ignore_unreachable: true
|
||||
block:
|
||||
- name: Wyłączenie logowania hasłem w SSH
|
||||
ansible.builtin.lineinfile:
|
||||
|
||||
Reference in new issue
Block a user