I am trying to print a custom message, when certain host is unreachable. My problem is, when the host is unreachable, it will be skipped on the next task, thus the fail module will never be triggered.
And the host that is reachable, will also skip the task due to the when condition are not met
.
I have tried ignore_unreachable: false
, still the same.
Any idea would be appreciated.
---
- hosts: prod
gather_facts: no
tasks:
- name: fail when not reachable
action: ping
register: ping_result
# any_errors_fatal: true
- fail:
msg: "please make sure all server up and run again"
when: ping_result.unreachable is defined
any_errors_fatal: true