-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet_ping.yml
More file actions
115 lines (102 loc) · 3.11 KB
/
net_ping.yml
File metadata and controls
115 lines (102 loc) · 3.11 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
- hosts: localhost
remote_user:
become: true
vars:
#Do not edit me
- ip_oct1_set: true
- ip_oct2_set: true
- ip_oct3_set: true
- ip_oct4_set: true
- good_ips: []
# ------------------
# Edit me for your needs
- ip_oct1: []
- ip_oct2: []
- ip_oct3: []
- ip_oct4: []
- ip_oct1_start: 0
- ip_oct1_end: 255
- ip_oct2_start: 0
- ip_oct2_end: 255
- ip_oct3_start: 0
- ip_oct3_end: 255
- ip_oct4_start: 0
- ip_oct4_end: 255
- retry: 0
- save_path: "/tmp/good_ips{{ ansible_date_time.date }}_{{ ansible_date_time.time }}.txt"
tasks:
- name: Check oct1 is set
set_fact:
ip_oct1_set: false
no_log: true
ignore_errors: true
when: ( ip_oct1 | length == 0 )
- name: Check oct2 is set
set_fact:
ip_oct2_set: false
no_log: true
ignore_errors: true
when: ( ip_oct2 | length == 0 )
- name: Check oct3 is set
set_fact:
ip_oct3_set: false
no_log: true
ignore_errors: true
when: ( ip_oct3 | length == 0 )
- name: Check oct4 is set
set_fact:
ip_oct4_set: false
no_log: true
ignore_errors: true
when: ( ip_oct4 | length == 0 )
- name: Set oct1
set_fact:
ip_oct1: "{{ ip_oct1 + [ item ] }}"
with_sequence: "start={{ ip_oct1_start }} end={{ ip_oct1_end }}"
when: ip_oct1_set == false
- name: Set oct2
set_fact:
ip_oct2: "{{ ip_oct2 + [ item ] }}"
with_sequence: "start={{ ip_oct2_start }} end={{ ip_oct2_end }}"
when: ip_oct2_set == false
- name: Set oct3
set_fact:
ip_oct3: "{{ ip_oct3 + [ item ] }}"
with_sequence: "start={{ ip_oct3_start }} end={{ ip_oct3_end }}"
when: ip_oct3_set == false
- name: Set oct4
set_fact:
ip_oct4: "{{ ip_oct4 + [ item ] }}"
with_sequence: "start={{ ip_oct4_start }} end={{ ip_oct4_end }}"
when: ip_oct4_set == false
- name: Ping the specified IP Ranges
local_action: "shell ping -a -c 1 -W 1 {{ item[0] }}.{{ item[1] }}.{{ item[2] }}.{{ item[3] }}"
register: result
retries: {{ retry }}
until: ('100% packet loss' not in result.stdout)
failed_when: ('100% packet loss' in result.stdout)
changed_when: false
ignore_errors: true
no_log: true
with_nested:
- "{{ ip_oct1 }}"
- "{{ ip_oct2 }}"
- "{{ ip_oct3 }}"
- "{{ ip_oct4 }}"
- name: Set good_ip variable
set_facts:
good_ips: "{{ good_ips }} + [ '{{ item.stdout | regex_search('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}' ]"
no_log: true
when: "'100% packet loss' not in item.stdout"
with_items: "{{ result.results }}"
- name: give pretty list of good ips
debug:
var: good_ips
- name: Make the file containing good_ips
copy:
content: "{{ good_ips }}"
dest: "{{ save_path }}"
- name: Inform where the file was made
debug:
msg: "A file has been made containing everything that was pingable: {{ save_path }}"