How to print only the failed telnet connections from my localhost

6 views
Skip to first unread message

Shifa Shaikh

unread,
Jun 29, 2020, 2:13:54 PM6/29/20
to Ansible Project
Below is my playbook that helps check telnet connections from my localhost to all remote hosts.

       - wait_for:

           host
: "{{ item }}"

           port
: 22

           state
: started         # Port should be open

           delay
: 0               # No wait before first check (sec)

           timeout
: 2             # Stop checking after timeout (sec)

         ignore_errors
: yes

         
register: netstatoutput

         delegate_to
: localhost

         with_items
: "{{ groups['all_hosts'] }}"


I get a lot of unnecessary stuff dumped in the logs when i debug like below:

   - debug:

       msg
: "{{ netstatoutput }}"

I just need all the failed telnet  IPs  printed in the debug and nothing else like below:

              "msg": "Timeout when waiting for 10.9.172.62:22"
             
"msg": "Timeout when waiting for 10.9.72.66:22"
             
"msg": "Timeout when waiting for 10.9.172.42:22"

....

Can you please suggest how can I? 
Reply all
Reply to author
Forward
0 new messages