Hi,
I have a group of hosts (say 3 hosts) of which one becomes unresponsive (due to heavy load or sshd is not running etc reasons). So eventually Ansible Playbook would fail with unreachable host message for that host. I want to handle this error and run a script locally (where the playbook is running from) to shutdown the unreachable host (there is an API from VMware where I can use to shutdown the VM without having to ssh to the remote VM). I am trying to simulate this by running a dummy script however my command is not executing for the unreachable host or it is executing for the good hosts as well (the ones that i can reach) but I don't want to. This is my playbook,
---
- hosts: "{{src}}_{{shard}}_test"
any_errors_fatal: true
gather_facts: False
max_fail_percentage: 0
tags:
- passivateSite
tasks:
- name: check SSH connection
ping:
register: result
ignore_errors: True
- debug: msg="System {{ inventory_hostname }}"
- name: if ssh connection failed then run this
command: /etc/ansible/test.sh red "@@@ Shutting down the VM @@@"
when: result|failed
ignore_errors: True
Any Clue? Or is there a way in ansible that I collect the failed hosts into another host group and only execute a command against these hosts?