# how do I ignore/handle the UNREACHABLE error?

**URL:** <https://forum.ansible.com/t/how-do-i-ignore-handle-the-unreachable-error/21418>\
**Category:** Ansible Project\
**Created:** [May 12, 2016, 4:42am UTC](https://forum.ansible.com/t/how-do-i-ignore-handle-the-unreachable-error/21418 "2016-05-12T04:42:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tegr9760](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@tegr9760](https://forum.ansible.com/u/tegr9760)\
**Post date:** [May 12, 2016, 4:42am UTC](https://forum.ansible.com/t/how-do-i-ignore-handle-the-unreachable-error/21418/1 "2016-05-12T04:42:36Z")

</div>

I’d like to find out how to ignore/handle the UNREACHABLE error. The reason is that I want to use Ansible to loop through my hosts monitored\_systems and if any of those systems ever get reimaged, then I want to reestablish ssh. Here’s what I have, but UNREACHABLE doesn’t honor “ignore\_errors: True”.

```auto
- hosts: monitored_systems
  gather_facts: False
  tasks:
  - name: ping system
    ping:
    register: result
    ignore_errors: True
  - name: if ping failed then run this
    command: script/estab_conn.sh {{ ansible_hostname }}
    when: result|failed
    delegate_to: localhost
  - name: rerun ping
    ping:
    when: result|failed

```

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [May 12, 2016, 7:39pm UTC](https://forum.ansible.com/t/how-do-i-ignore-handle-the-unreachable-error/21418/2 "2016-05-12T19:39:41Z")

</div>

I am having a similar or maybe not so similar issue. If I get a response on my thread on how to work out my issue or if I figure it out, I’ll let you know. Here is my thread so you can see how I am using the **failed\_when:** option

[https://groups.google.com/forum/#!topic/ansible-project/xomBvN6Qd9g](https://groups.google.com/forum/#!topic/ansible-project/xomBvN6Qd9g)

---

<div class="post-metadata">

**Author:** ![tegr9760](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@tegr9760](https://forum.ansible.com/u/tegr9760)\
**Post date:** [May 12, 2016, 7:46pm UTC](https://forum.ansible.com/t/how-do-i-ignore-handle-the-unreachable-error/21418/3 "2016-05-12T19:46:33Z")

</div>

It would be nice to know how to handle this, but what I ended up doing was calling a bash script that attempts to identify and fix the problem, and this is working. Here’s my playbook:

> * * *
> 
> - hosts: monitored\_systems
> 
> gather\_facts: false
> 
> tasks:
> 
> - debug: var=inventory\_hostname
> 
> - name: ssh into the system
> 
> local\_action: shell scripts/verify\_connection.sh {{ inventory\_hostname }}

and then here is my script:

> #!/bin/bash
> 
> RC=0
> 
> ansible $1 -m ping
> 
> if [$? -eq 0]
> 
> then
> 
> echo “success”
> 
> else
> 
> echo “failure”
> 
> ping -w 3 -i 0.5 $1
> 
> if [$? -eq 0]
> 
> then
> 
> echo “Can do normal ping so the machine is up”
> 
> sshpass -f password.txt ssh-copy-id root@$1
> 
> if [$? -ne 0]
> 
> then
> 
> echo “Unable to ssh-copy-id, try removing key and retrying next time”
> 
> ssh-keygen -f “/root/.ssh/known\_hosts” -R $1
> 
> RC=1
> 
> else
> 
> echo “success on ssh-copy-id”
> 
> sshpass -f password.txt ssh -q root@$1 exit
> 
> if [$? -ne 0]
> 
> then
> 
> echo “Unable to ssh”
> 
> RC=1
> 
> else
> 
> echo “successfully sshd”
> 
> fi
> 
> fi
> 
> ansible $1 -m ping
> 
> if [$? -eq 0]
> 
> then
> 
> echo “Ansible is able to connect”
> 
> else
> 
> echo “Failure”
> 
> RC=1
> 
> fi
> 
> fi # normal ping check
> 
> fi
> 
> exit $RC

Then I just call it every few minutes.
