--- - 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: 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) }}" run_once: true # noqa: run-once[task] delegate_to: localhost - name: Successful Hosts ansible.builtin.debug: var: successful_hosts run_once: true # noqa: run-once[task] delegate_to: localhost - name: Failed Hosts ansible.builtin.debug: var: failed_hosts run_once: true # noqa: run-once[task] delegate_to: localhost ...