--- - 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: Display ping results run_once: true # noqa: run-once[task] block: - name: Successful Hosts ansible.builtin.debug: msg: "{{ successful_hosts | default([]) + ansible_play_batch }}" delegate_to: localhost - name: Failed Hosts ansible.builtin.debug: msg: "{{ failed_hosts | default([]) + ansible_play_hosts_all | difference(ansible_play_batch) }}" delegate_to: localhost ...