Ansible skip unreachable hosts

ansible fail
ansible failed_when: false
ansible check_mode
ansible retry
ansible no_log
ansible-playbook return code
ansible check host reachable
ansible block run_once

Hello I have written a script to ping all my inventory hosts. Some are behind VPN services so before I can ping them I set up a tunnel.

This works fine, however if the tunnel is set up but the ansible ping does not succeed the entire play just halts and none of the subsequent tasks get executed ( tunnel does not get closed / rest of tasks for host that are reachable do not get executed )

How can I make the play continue and just skip the host that was unreachable? I've looked at "meta clear_host_errors" but that's not it.

Here's my script

- hosts:
    - liveservers-direct
    - liveservers-special
    - liveservers-keypair
    - testservers-direct
    - testservers-special
    - testservers-keypair
    - intern
  gather_facts: no
  strategy: debug
  become: no
  - name: Ping some servers

- hosts:
    - liveservers-vpn
    - testservers-vpn
  strategy: debug
  gather_facts: no
  become: no
  serial: 1
   - ../roles/vpn/vars/customers.yml
  - include: ../roles/vpn/tasks/connect.yml icao="{{hostvars[inventory_hostname]['icao']}}"
  - ping:
  - name:
    meta: clear_host_errors
  - include: ../roles/vpn/tasks/disconnect.yml icao="{{hostvars[inventory_hostname]['icao']}}"

fatal: [server.behind.vpn]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 10.xx.xx.xx port 22: Connection timed out\r\n", "unreachable": true}

above error happens on "ping" how do I make it skip the failure and just continue with the rest of the hosts? the play just stops now when it reaches the unreachable host, but a few more need to be checked

This will soon be possible in the upcoming 2.7 release of Ansible, with the ignore_unreachable keyword.

See the release notes for 2.7 -

New keyword ignore_unreachable for plays and blocks. Allows ignoring tasks that fail due to unreachable hosts, and check results with is unreachable test.

ansible: silently skip unreachable hosts, Going to add this answer: a fix was added in Ansible 2.7:  Make sure this host can be reached over ssh", "unreachable": true} It's easy enough to work around this problem, though! If you have the ability to build your own base images (e.g. AMIs on AWS), you can just make sure /usr/bin/python is already installed on the image.

You could try using ignore_errors: yes. It will ignore any errors no matter what the reason is and it will continue with the rest of the tasks.


Error Handling In Playbooks, Ignoring Failed Commands; Resetting Unreachable Hosts; Handlers and Failure to abort the entire play on failure, not just skip remaining tasks for a host. As @alikins states above, the ignore_errors feature is designed to capture task errors, connection errors are not affected by it as the task never had a chance to execute. If you need to clear unreachable errors you can use a meta: clear_host_errors task to reinstate all unreachable hosts into the play. In

Removing serial keyword did fix the issue with the play being halted on an unreachable host. However my VPN connection play isn't written with parallel processing in mind and so I'll have to change that.

Play still fails for "UNREACHABLE" hosts even with "ignore_errors , Play still fails for "UNREACHABLE" hosts even with "ignore_errors: true" set Ansible should be able to skip the unreachable and go forward. Issue Type : Feature Idea Ansible Version : 2.1 Component Name : Task In my playbook I have a task which should not run for a particular host from my inventory. Also another Task which should run only for that host from my inventory The

Anisble does not allow handling of "host unreachable" errors · Issue , ISSUE TYPE Bug Report COMPONENT NAME Anible core (?) ANSIBLE VERSION ansible config file  After testing, it seems - meta: clear_host_errors (and refresh_inventory) does not clear unreachable host errors. This might be related meta: clear_host_errors not working on tasks #19673 . This comment has been minimized.

Ignore Unreachable hosts : ansible, Ignore Unreachable hosts. Hey Reddit,. I'm running AWX 9.2 in my environment and I'm trying to solve a problem. I have a range of 30 IP's that are used for a  Running Ansible inside Vagrant/Virtualbox on Windows to provision remote VMs. Both machines running Ubuntu 16.04. Ansible version Ansible config file is located in /ansible/ansible.cfg. hosts line: raw1 ansible_host=xx.xx.xx.xx ansible_port=22 ansible_user=root ansible_ssh_pass=wer32dw This fails:

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  Removed in Ansible: version: 2.11: Why: The ‘default’ callback plugin now supports this functionality: Alternative: ‘default’ callback plugin with ‘display_skipped_hosts = no’ option

  • Why serial: 1?
  • Thought it would be more stable to do the servers behind a VPN one by one. ( these aren't many )
  • How about solving your problem by removing it?
  • doesn't work it just opens a tunnel to the first host and all the other tunnels fail. things got worse
  • I think your problem stems from how you organized your plays. You have a whole play that connects to the vpn, pings, and disconnects, so if this play fails it will not continue to the next play. When a play fails it brings the whole playbook to a stop. I would investigate combining these two very similar plays into one play using when to distinguish host (or really group) specific tasks.
  • This only ignores task errors not connection errors.