3
votes

I have an Ansible playbook that is used to automate the backup of a server and database (both on the same VM).

Last night during the middle of the playbook's run, rsync ran into a host unreachable error and the playbook failed. I was unaware that the "rescue" part of the blocks will not be executed in the case of a host unreachable. This caused the rescue to not be run and the service we were backing up did not come online, meaning that many people were unable to do work in the morning.

I'm looking for a way to catch the host unreachable error within something like a "failed_when" so that I can execute a task to start the service in the off chance that this happens again.

Does anyone have any ideas?

3
Can you post your playbook (at least the block/rescue part)?helloV
If you use block/rescue/always inside the include, be aware that there are unresolved issues in Ansible: github.com/ansible/ansible/issues/15963Konstantin Suvorov

3 Answers

0
votes

As of right now this is not possible with Ansible. It is a known issue.

0
votes

Nowdays there is an easy way to ignore unreachable hosts. ignore_unreachable: true

0
votes

Handling unreachable host with conditional follow-up (a-better-than-nothing solution):

tasks:

  - name: This task will fail
    command: /bin/false
    ignore_unreachable: true
    register: command_result

  - name: This task will start only if host is unreachable
    command: /bin/true
    when: command_result.stdout is undefined