how do I ignore/handle the UNREACHABLE error?

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”.

- 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

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

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.