-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIP_Finder.yaml
More file actions
114 lines (93 loc) · 3.36 KB
/
IP_Finder.yaml
File metadata and controls
114 lines (93 loc) · 3.36 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
---
- name: Check IPs against a subnet
hosts: windows
#ansible_all_ipv4_addresses
vars:
# Define the base IP and subnet
ci_ip: "192.168.1.120/24"
# List of IPs to check
mediaServer_ipList:
- "192.168.1.10"
- "192.168.1.200"
- "192.168.2.10"
- "10.0.0.1"
tasks:
#- name: Filter IPs that belong to the subnet
#set_fact:
#matching_ips: "{{ mediaServer_ipList | ansible.utils.ipaddr(ci_ip)}}"
#delegate_to: localhost
#- name: Display matching IPs
#debug:
#msg: "IPs in the subnet {{ ci_ip }}: {{ matching_ips }}"
- name: Display Windows BackupClient IP
debug:
msg: "{{ansible_interfaces | json_query('[*].ipv4')}}"
when: ansible_system == 'Win32NT'
#delegate_to: 192.168.1.23
#delegate_facts: true
#run_once: true
- name: Display Linux BackupClient IP
shell: "ip addr | grep 'inet ' | grep -v '127.0.' | awk {'print $2'}"
when: ansible_system == 'Linux'
- name: Set_Backup Client IP
set_fact:
ip_prefix_list: "{{ ansible_interfaces | json_query('[*].ipv4') | list}}"
- name: Format Backup Client IP
set_fact:
formatted_ip_prefix_list: "{{ ip_prefix_list | map(attribute='address') | zip(ip_prefix_list | map(attribute='prefix')) | map('join', '/') | list }}"
- name: Display MediaServer IPs
shell: "ip addr | grep 'inet ' | grep -v '127.0.' | awk {'print $2'} | awk -F '/' {'print $1'}"
register: mediaIP
delegate_to: 192.168.1.24
run_once: true
- name: Set_MediaServerIP List
set_fact:
mediaServer_ipList: "{{mediaIP.stdout_lines | list}}"
- name: MediaIP Lists to Validate
debug:
var: mediaServer_ipList
- name: Debug
debug:
msg: "{{ mediaServer_ipList | ansible.utils.ipaddr(item)}}"
loop: "{{formatted_ip_prefix_list}}"
- name: Init Matching IPs
set_fact:
matched_ips: []
- name: Check each media server IP against each prefix
loop: "{{ mediaServer_ipList | product(formatted_ip_prefix_list) | list }}"
loop_control:
loop_var: ip_pair
vars:
media_ip: "{{ ip_pair[0] }}"
ip_prefix: "{{ ip_pair[1] }}"
when: media_ip | ansible.utils.ipaddr(ip_prefix)
set_fact:
matched_ips: "{{ matched_ips + [media_ip] }}"
# - name: Filter IPs that belong to the subnet
# set_fact:
# matching_ips: "{{ matching_ips + [ip] }}"
# loop: "{{formated_ip_prefix_list}}"
# vars:
# ip: "{{item}}"
# when: formated_ip_prefix_list | select(ansible.utils.ipaddr(ip)) | list | length > 0
#
- name: Display matching IPs
debug:
msg: "{{ matched_ips }}"
# - name: Debug error hadnling
# set_fact:
# matched_ips:
# - 192.168.1.24
# - 192.168.1.1
#
- name: Usable Media IP
set_fact:
media_ip: []
- name: finalize
include_tasks: IP_updater.yaml
loop: "{{matched_ips}}"
#
# # - name: Print IP addresses and prefixes
#debug:
#msg: "{{ansible_all_ipv4_addresses}}"
#msg: "{{ ansible_all_ipv4_addresses | zip(ansible_all_ipv4_prefixes) | list }}"