40 lines
1.4 KiB
YAML
40 lines
1.4 KiB
YAML
---
|
|
- name: Test dostępności hostów oraz logowania SSH
|
|
hosts: all
|
|
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' }}" |