-
Notifications
You must be signed in to change notification settings - Fork 54
/
handle_unreachable_hosts_method_3.yml
36 lines (31 loc) · 1.27 KB
/
handle_unreachable_hosts_method_3.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---
# in this method, the playbook will show as success in Tower, listing unreachable systems as unreachable at the end
# unreachable systems identified in the first play
# any tasks/roles can be executed in the 2nd play on reachable systems
# result: all tasks are executed on all reachable systems
- name: ping hosts
hosts: all
gather_facts: false
tasks:
- block:
- name: ping host
win_ping:
ignore_unreachable: true
always:
- name: add reachable hosts to a new group
add_host:
name: "{{ inventory_hostname }}"
group: reachable_hosts
- debug:
msg: "failed hosts: {{ ansible_play_hosts_all | difference(groups.reachable_hosts) }}"
run_once: true
# you can take any action here on behalf of failed hosts
# remember to use (run_once: true) and (delegate_to: localhost) as appropriate
# why delegate_to: localhost? you might ask. Imagine a scenario where all hosts failed.
# in that case, there are no hosts to execute any tasks on, you can delegate_to: localhost for any action needed
# for example send email, make api call to update a record somewhere etc.
- name: other play
hosts: reachable_hosts
tasks:
- debug:
msg: "{{ inventory_hostname }} is reachable"