Skip to content

Instantly share code, notes, and snippets.

@t04glovern
Created April 26, 2022 13:52
Show Gist options
  • Save t04glovern/e62410abcd9e0fccc09d004e5eb7bd90 to your computer and use it in GitHub Desktop.
Save t04glovern/e62410abcd9e0fccc09d004e5eb7bd90 to your computer and use it in GitHub Desktop.
Ansible ignore all future tasks for unreachable hosts
---
- name: Identify reachable hosts
hosts: all
connection: local
gather_facts: false
tasks:
- block:
- name: determine hosts that are reachable
ansible.builtin.wait_for_connection:
timeout: 10
vars:
ansible_connection: ssh
- name: add devices with connectivity to the "reachable" group
ansible.builtin.group_by:
key: reachable
rescue:
- name: debug print unreachable host(s)
ansible.builtin.debug: msg="cannot connect to {{ inventory_hostname }}"
- name: Provision reachable hosts
hosts: reachable
tasks:
- name: debug print reachable host(s)
ansible.builtin.debug: msg="{{ inventory_hostname }} is reachable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment