-
Notifications
You must be signed in to change notification settings - Fork 6
/
ip_range.yml
57 lines (49 loc) · 1.91 KB
/
ip_range.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
# ansible-playbook ip_range.yml
# IP range JSON example from: https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html#aws-ip-syntax
- name: Play around with IP address ranges
hosts: localhost
connection: local
become: false
gather_facts: false
vars:
input: "{{ lookup('file','files/ip_addresses.json') | from_json }}"
test_list: ['192.0.2.18', 'host.fqdn', '::1', '192.168.32.0/24', 'fe80::100/10',
'2001:db8:cafe::f00/64', true, '', '42540766412265424405338506004571095040/64']
tasks:
- name: Create IPv4 List
set_fact:
ipv4_list: "{{ input.prefixes }}"
- name: Create IPv6 List
set_fact:
ipv6_list: "{{ input.ipv6_prefixes }}"
- name: TEST 1
block:
- name: Loop over IPv4 addresses
debug:
msg: "{{ item.ip_prefix }}"
with_items: "{{ ipv4_list }}"
- name: TEST 2
block:
- name: Print first and last ip of an IPv4 range (query by index number)
debug:
msg: "{{ item.ip_prefix | ipaddr('1') | ipv4('address') }}-{{ item.ip_prefix | ipaddr('-1') | ipv4('address') }}"
with_items: "{{ ipv4_list }}"
- name: TEST 3
block:
- name: Print first and last ip of an IPv6 range (query by index number)
debug:
msg: "{{ item.ipv6_prefix | ipaddr('1') | ipv6('address') }}-{{ item.ipv6_prefix | ipaddr('-1') | ipv6('address') }}"
with_items: "{{ ipv6_list }}"
- name: TEST 4
block:
- name: Check if values in 'test_list' are in the range of an IPv4 prefix
debug:
msg: "{{ test_list | ipaddr(item.ip_prefix) }}"
with_items: "{{ ipv4_list }}"
- name: TEST 5
block:
- name: Check if values in 'test_list' are in the range of an IPv6 prefix
debug:
msg: "{{ test_list | ipaddr(item.ipv6_prefix) }}"
with_items: "{{ ipv6_list }}"