-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkhostsup.yml
40 lines (36 loc) · 1.12 KB
/
checkhostsup.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
37
38
39
40
---
- name: Checking for up hosts
hosts: all
gather_facts: False
tasks:
- block:
- name: determine hosts that are up
wait_for_connection:
timeout: 5
vars:
ansible_connection: ssh
- name: add devices with connectivity to the "running_hosts" group
group_by:
key: "running_hosts"
rescue:
- name: Send Alert to Slack
community.general.slack:
token: "{{ slack_token }}"
msg: "Ansible failed on *({{ inventory_hostname }})* \n
*Task*: {{ ansible_failed_task.name }} \n
*Action*: {{ ansible_failed_task.action }} \n
*Error Message*: \n ```{{ ansible_failed_result | to_nice_json }}``` "
channel: "{{ channel }}"
username: "{{ slackuser }}"
run_once: true
delegate_to: localhost
- name: Gather facts from running_hosts
hosts: running_hosts
gather_facts: True
tasks:
- name: Facts
ansible.builtin.setup:
register: all_facts
- name: Facts Debug
ansible.builtin.debug:
var: all_facts