Print (debug: msg) unreachable hosts

74 views
Skip to first unread message

Darko Milodanović

unread,
Sep 6, 2017, 2:15:32 PM9/6/17
to Ansible Project

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 :)

Kai Stian Olstad

unread,
Sep 6, 2017, 3:46:47 PM9/6/17
to ansible...@googlegroups.com
On onsdag 6. september 2017 20.15.32 CEST Darko Milodanović wrote:
> Is there a way to register unreachable hosts and print them afterwards
> using debug/msg??

Yes.

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


--
Kai Stian Olstad
Reply all
Reply to author
Forward
Message has been deleted
0 new messages