47 lines
1.3 KiB
YAML
47 lines
1.3 KiB
YAML
---
|
|
- name: Ping check to determine if hosts are reachable
|
|
hosts: all
|
|
become: true
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
- name: Wait for connection
|
|
ansible.builtin.wait_for_connection:
|
|
timeout: 5
|
|
|
|
- name: Test target host connectivity
|
|
ansible.builtin.command:
|
|
cmd: whoami
|
|
changed_when: false
|
|
register: ping_check
|
|
ignore_errors: true
|
|
failed_when: false
|
|
|
|
- name: Clear host errors
|
|
ansible.builtin.meta: clear_host_errors
|
|
|
|
# - name: Ping check results
|
|
# ansible.builtin.debug:
|
|
# msg: "{{ lookup('template', 'ping_results.j2') | from_yaml }}"
|
|
# run_once: true # noqa: run-once[task]
|
|
# delegate_to: localhost
|
|
|
|
- name: Set facts
|
|
ansible.builtin.set_fact:
|
|
successful_hosts: "{{ successful_hosts | default([]) + ansible_play_batch }}"
|
|
failed_hosts: "{{ failed_hosts | default([]) + ansible_play_hosts_all | difference(ansible_play_batch) }}"
|
|
|
|
- name: Successful Hosts
|
|
ansible.builtin.debug:
|
|
msg: "{{ successful_hosts }}"
|
|
run_once: true # noqa: run-once[task]
|
|
delegate_to: localhost
|
|
|
|
- name: Failed Hosts
|
|
ansible.builtin.debug:
|
|
msg: "{{ failed_hosts }}"
|
|
run_once: true # noqa: run-once[task]
|
|
delegate_to: localhost
|
|
|
|
...
|