From 54d6529b5f69b0e851248347927b2685e048381c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=BBbikowski?= Date: Tue, 11 Aug 2026 20:55:53 +0200 Subject: [PATCH] Add ansible/ping_check.yml --- ansible/ping_check.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ansible/ping_check.yml diff --git a/ansible/ping_check.yml b/ansible/ping_check.yml new file mode 100644 index 0000000..62e9f25 --- /dev/null +++ b/ansible/ping_check.yml @@ -0,0 +1,40 @@ +--- +- name: Test dostępności hostów oraz logowania SSH + hosts: nni + gather_facts: false # Wyłączone, aby playbook nie wywalił się na wstępie na niedostępnych maszynach + + tasks: + # 1. SPRAWDZENIE PING (ICMP) + - name: Sprawdź odpowiadanie na ping (ICMP) + ansible.builtin.command: "ping -c 2 -W 2 {{ inventory_hostname }}" + delegate_to: localhost + register: icmp_result + ignore_errors: true + changed_when: false + + # 2. SPRAWDZENIE PORTU SSH (TCP 22) + - name: Sprawdź czy port SSH (22) jest otwarty + ansible.builtin.wait_for: + host: "{{ inventory_hostname }}" + port: 22 + state: started + delay: 0 + timeout: 3 + delegate_to: localhost + register: ssh_port_result + ignore_errors: true + + # 3. SPRAWDZENIE LOGOWANIA SSH (Ansible Ping) + - name: Próba zalogowania się przez SSH + ansible.builtin.ping: + register: ssh_login_result + ignore_errors: true + + # 4. PODSUMOWANIE DLA DANEGO HOSTA + - name: Podsumowanie stanu hosta + ansible.builtin.debug: + msg: + - "Host: {{ inventory_hostname }}" + - "PING (ICMP): {{ 'OK' if icmp_result.rc == 0 else 'FAIL' }}" + - "Port SSH (22): {{ 'OTWARTY' if not ssh_port_result.failed else 'ZAMKNIĘTY/TIMEOUT' }}" + - "Logowanie SSH: {{ 'SUKCES' if not ssh_login_result.failed else 'BŁĄD LOGOWANIA' }}" \ No newline at end of file