Print (debug: msg) unreachable hosts

Is there a way to register unreachable hosts and print them afterwards using debug/msg??

  • name: check if the node is UP
    shell: echo {{inventory_hostname}}
    register: ping_test

  • name: show debug
    debug:
    var: ping_test

This is basically what i did , but it will not show unreachable hosts, only those that have succeeded .

Further i would like to do something like this:

  • name: Append to file if the node is down
    lineinfile:
    dest: “/tmp/hdd_check.log”
    line: “{{ inventory_hostname }},DOWN”
    insertafter: EOF
    when: ping_test|failed
    ignore_errors: true

But i cannot because the host is not registered when it’s unreachable.

Please help :slight_smile:

Yes.

- name: Unreatchable hosts
  debug: msg="Host unreatchable - {{ item }}"
  with_items: "{{ ansible_play_hosts_all | difference(ansible_play_hosts) }}"