Handle Host Unreachable cases or Test SSH Connectivity in yml playbook

846 views
Skip to first unread message

Anas Theo

unread,
Oct 13, 2016, 9:42:24 AM10/13/16
to Ansible Project
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. 

Kai Stian Olstad

unread,
Oct 13, 2016, 11:07:09 AM10/13/16
to ansible...@googlegroups.com
On 13. okt. 2016 15:42, 'Anas Theo' via Ansible Project wrote:
> 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

---
- hosts: all
any_errors_fatal: true
pre_tasks:
- ping:

--
Kai Stian Olstad

Anas Theo

unread,
Oct 13, 2016, 3:46:39 PM10/13/16
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages