Files
semaphore/ansible/beszel_agent.yml

84 lines
2.9 KiB
YAML

---
- 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') }}"