From 10046d522ea9c29a80091e1ce83a839d8b3060af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=BBbikowski?= Date: Tue, 11 Aug 2026 23:37:17 +0200 Subject: [PATCH] Add ansible/beszel_agent.yml --- ansible/beszel_agent.yml | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ansible/beszel_agent.yml diff --git a/ansible/beszel_agent.yml b/ansible/beszel_agent.yml new file mode 100644 index 0000000..c3453e4 --- /dev/null +++ b/ansible/beszel_agent.yml @@ -0,0 +1,84 @@ +--- +- name: Instalacja Beszel Agent + hosts: all + become: true + gather_facts: false + + # ========================================== + # DOMYŚLNE ZMIENNE (Można nadpisać w Semaphore) + # ========================================== + vars: + beszel_port: "45876" + beszel_key: "ssh-ed25519 AAAACxxxxxx" + beszel_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + beszel_url: "http://beszel.example.org:8090" + + tasks: + # ========================================== + # SPRAWDZENIE DOSTĘPNOŚCI (SKIP + PING + SSH) + # ========================================== + - 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) }}" + 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 + + # ========================================== + # INSTALACJA BESZEL AGENT + # ========================================== + - name: Pobranie i instalacja Beszel Agent + when: + - not (skip | default(false)) + - host_is_online | default(false) + ignore_unreachable: true + block: + - name: Pobranie skryptu instalacyjnego Beszel + ansible.builtin.get_url: + url: "https://get.beszel.dev" + dest: "/tmp/install-agent.sh" + mode: "0755" + + - name: Wykonanie skryptu instalacyjnego Beszel Agent + ansible.builtin.command: > + /tmp/install-agent.sh + -p {{ beszel_port }} + -k "{{ beszel_key }}" + -t "{{ beszel_token }}" + -url "{{ beszel_url }}" + --auto-update + register: beszel_install + changed_when: "'Installation complete' in beszel_install.stdout or beszel_install.rc == 0" + + - name: Usunięcie pliku instalacyjnego z /tmp + ansible.builtin.file: + path: "/tmp/install-agent.sh" + state: absent + + # ========================================== + # PODSUMOWANIE + # ========================================== + - name: Informacja o stanie wykonania + ansible.builtin.debug: + msg: + - "Host: {{ inventory_hostname }}" + - "Status: {{ '⏭️ POMINIĘTO (skip: true)' if (skip | default(false)) else ('🔴 OFFLINE / UNREACHABLE' if not (host_is_online | default(false)) else '✅ ZAINSTALOWANO BESZEL AGENT') }}" \ No newline at end of file