Check if host reachable via Ansible playbook

Mindwatering Incorporated

Author: Tripp W Black

Created: 12/03 at 03:54 PM

 

Category:
Linux
RH AAP

Task:
As an alternative of failing a subsequent task, add a check to see if a host is reachable first.

In a real-world example, the reg_connection_check.skip_reason would be the when for all subsequent calls (e.g. tasks or to a child role).


Code Snippet:
...
- shell: hostname
register: reg_connection_check
- wait_for_connection:
msg: "Server is unreachable"
when:
- reg_connection_check.skip_reason is defined
- "'unreachable' in reg_connection_check.skip_reason"
...


previous page

×