1
votes

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
  tasks:
  - name: Ping some servers
    ping:


- hosts:
    - liveservers-vpn
    - testservers-vpn
  strategy: debug
  gather_facts: no
  become: no
  serial: 1
  vars_files:
   - ../roles/vpn/vars/customers.yml
  tasks:
  - 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

2
Why serial: 1?techraf
Thought it would be more stable to do the servers behind a VPN one by one. ( these aren't many )Synbitz Prowduczions
How about solving your problem by removing it?techraf
doesn't work it just opens a tunnel to the first host and all the other tunnels fail. things got worseSynbitz Prowduczions
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.Andrew H

2 Answers

10
votes

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 - https://github.com/ansible/ansible/blob/stable-2.7/changelogs/CHANGELOG-v2.7.rst#major-changes

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

-3
votes

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.