# Handle Host Unreachable cases or Test SSH Connectivity in yml playbook

**URL:** <https://forum.ansible.com/t/handle-host-unreachable-cases-or-test-ssh-connectivity-in-yml-playbook/22785>\
**Category:** Ansible Project\
**Created:** [October 13, 2016, 1:42pm UTC](https://forum.ansible.com/t/handle-host-unreachable-cases-or-test-ssh-connectivity-in-yml-playbook/22785 "2016-10-13T13:42:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anas\_Theo](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Anas\_Theo](https://forum.ansible.com/u/Anas_Theo)\
**Post date:** [October 13, 2016, 1:42pm UTC](https://forum.ansible.com/t/handle-host-unreachable-cases-or-test-ssh-connectivity-in-yml-playbook/22785/1 "2016-10-13T13:42:24Z")

</div>

Hello,

Is there any easy way to handle “host unreachable” cases in order to debug in a log file the problematic situation ? As an alternative it could also be useful to test SSH connectivity through explicit commands in all remote hosts before executing the rest of the .yml file. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 13, 2016, 3:06pm UTC](https://forum.ansible.com/t/handle-host-unreachable-cases-or-test-ssh-connectivity-in-yml-playbook/22785/2 "2016-10-13T15:06:27Z")

</div>

If you have gather\_facts as true and set "any\_errors\_fatal: true", it will stop at the setup task(gathering of facts) and not proceed any task or roles if one host fails.

If gather\_facts is false you can make a dummy task with ping module in pre\_tasks like so

---

<div class="post-metadata">

**Author:** ![Anas\_Theo](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@Anas\_Theo](https://forum.ansible.com/u/Anas_Theo)\
**Post date:** [October 13, 2016, 7:46pm UTC](https://forum.ansible.com/t/handle-host-unreachable-cases-or-test-ssh-connectivity-in-yml-playbook/22785/3 "2016-10-13T19:46:39Z")

</div>

Hello Kai,

Indeed, I can use ping to test the connectivity in all servers, hower the fatar error again can’t be handled for example in a conditional form.

What I request is to be able to handle this result “fatal: [sles\_11]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh.”, “unreachable”: true}” , in order to for example to be able to write a message in a local log file.

This case is also describer in documentation of ansible:  
“You can change this behavior with the `--force-handlers` command-line option, or by including `force_handlers: True` in a play, or `force_handlers = True` in ansible.cfg. When handlers are forced, they will run when notified even if a task fails on that host. (Note that certain errors could still prevent the handler from running, such as a host becoming unreachable.)”

Is there any option to overcome this problem?

Thank you very much.

Τη Πέμπτη, 13 Οκτωβρίου 2016 - 4:42:24 μ.μ. UTC+3, ο χρήστης Anas Theo έγραψε:
