--- - name: Test dostępności hostów oraz logowania SSH hosts: all gather_facts: false tasks: # ========================================== # 1. SPRAWDZENIE PING (ICMP) # ========================================== - name: Test PING (ICMP) block: - name: Wykonaj ping do hosta ansible.builtin.command: "ping -c 2 -W 2 {{ inventory_hostname }}" delegate_to: localhost changed_when: false - name: Ustaw wynik PING jako OK ansible.builtin.set_fact: icmp_status: "OK" rescue: - name: Ustaw wynik PING jako FAIL ansible.builtin.set_fact: icmp_status: "FAIL" # ========================================== # 2. SPRAWDZENIE PORTU SSH (TCP 22) # ========================================== - name: Test portu SSH (TCP 22) block: - name: Sprawdź otwarcie portu 22 ansible.builtin.wait_for: host: "{{ inventory_hostname }}" port: 22 state: started delay: 0 timeout: 3 delegate_to: localhost - name: Ustaw wynik portu SSH jako OTWARTY ansible.builtin.set_fact: ssh_port_status: "OTWARTY" ssh_port_open: true rescue: - name: Ustaw wynik portu SSH jako ZAMKNIĘTY ansible.builtin.set_fact: ssh_port_status: "ZAMKNIĘTY/TIMEOUT" ssh_port_open: false # ========================================== # 3. SPRAWDZENIE LOGOWANIA SSH # ========================================== - name: Test logowania po SSH (Ansible Ping) when: ssh_port_open block: - name: Próba zalogowania i wykonania modułu ping ansible.builtin.ping: - name: Ustaw wynik logowania jako SUKCES 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Ń" # ========================================== # 4. PODSUMOWANIE DLA DANEGO HOSTA # ========================================== - name: Podsumowanie stanu hosta ansible.builtin.debug: msg: - "Host: {{ inventory_hostname }}" - "PING (ICMP): {{ icmp_status }}" - "Port SSH (22): {{ ssh_port_status }}" - "Logowanie SSH: {{ ssh_login_status | default('POMINIĘTO (Port zamknięty)') }}"