# when Host Unreachable, execute a command or a script only for the failed host

**URL:** <https://forum.ansible.com/t/when-host-unreachable-execute-a-command-or-a-script-only-for-the-failed-host/22067>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [July 20, 2016, 9:07pm UTC](https://forum.ansible.com/t/when-host-unreachable-execute-a-command-or-a-script-only-for-the-failed-host/22067 "2016-07-20T21:07:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudarsan\_Mukundhan](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Sudarsan\_Mukundhan](https://forum.ansible.com/u/Sudarsan_Mukundhan)\
**Post date:** [July 20, 2016, 9:07pm UTC](https://forum.ansible.com/t/when-host-unreachable-execute-a-command-or-a-script-only-for-the-failed-host/22067/1 "2016-07-20T21:07:42Z")

</div>

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,
