Handle Host Unreachable cases or Test SSH Connectivity in yml playbook

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.

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

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 έγραψε: