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
---- hosts: monitored_systemsgather_facts: falsetasks:- debug: var=inventory_hostname- name: ssh into the systemlocal_action: shell scripts/verify_connection.sh {{ inventory_hostname }}
#!/bin/bashRC=0ansible $1 -m pingif [ $? -eq 0 ]thenecho "success"elseecho "failure"ping -w 3 -i 0.5 $1if [ $? -eq 0 ]thenecho "Can do normal ping so the machine is up"sshpass -f password.txt ssh-copy-id root@$1if [ $? -ne 0 ]thenecho "Unable to ssh-copy-id, try removing key and retrying next time"ssh-keygen -f "/root/.ssh/known_hosts" -R $1RC=1elseecho "success on ssh-copy-id"sshpass -f password.txt ssh -q root@$1 exitif [ $? -ne 0 ]thenecho "Unable to ssh"RC=1elseecho "successfully sshd"fifiansible $1 -m pingif [ $? -eq 0 ]thenecho "Ansible is able to connect"elseecho "Failure"RC=1fifi # normal ping checkfiexit $RC