Skip to content

Instantly share code, notes, and snippets.

@vic501
Forked from t04glovern/playbook.yml
Created March 4, 2023 05:38
Show Gist options
  • Save vic501/9e3d837fe97950b8138b5da671ac21d3 to your computer and use it in GitHub Desktop.
Save vic501/9e3d837fe97950b8138b5da671ac21d3 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