Created
April 26, 2022 13:52
-
-
Save t04glovern/e62410abcd9e0fccc09d004e5eb7bd90 to your computer and use it in GitHub Desktop.
Ansible ignore all future tasks for unreachable hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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