How to print only the failed telnet connections from my localhost

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?