-
Notifications
You must be signed in to change notification settings - Fork 11
/
ipaddr.yml
97 lines (97 loc) · 3.03 KB
/
ipaddr.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
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
---
# Based on https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters_ipaddr.html#playbooks-filters-ipaddr
- name: Using ipaddr filter and check on ip address variables
hosts: localhost
gather_facts: False
vars:
ipv4_addresses:
- 192.168.0.1/24
- 192.168.1.1/24
- 192.168.1.1/27
- 192.168.1.1/32
- 192.168.4.8/24
- 192.168.1.1/255.255.255.248
ipv6_addresses:
- FD00:00:00:01::1/64
- FDG0:00:00:01::1
- FE80:00::1/64
- 2001:db8::1/64
- 2001:DB8::1/64
tasks:
- name: get ipv4 wildcard mask
debug:
msg: "entry: {{ item }}
wilcard_mask: {{ item | ipaddr('hostmask') }}
host_address: {{ item | ipaddr('host') }}
netmask: {{ item | ipaddr('netmask') }}
network: {{ item | ipaddr('network') }}
prefix: {{ item | ipaddr('prefix') }}"
loop: "{{ ipv4_addresses }}"
- name: get best supernet
debug:
msg: "{{ ipv4_addresses | cidr_merge('span') }}"
- name: get supernets
debug:
msg: "{{ ipv4_addresses | ipaddr('network/prefix') | cidr_merge }}"
register: supernets
- name: print supernets
debug:
msg: "Entry: {{ item }}"
loop: "{{ supernets.msg }}"
- name: ipv6 formed
debug:
msg: "Entry: {{ item }} formed: {{ item | ipaddr('host') }}"
loop: "{{ ipv6_addresses | upper }}"
when:
- item | ipv6
- item | upper
- name: is ipv6 link-local ?
debug:
msg: "Entry: {{ item }} is a Link Local Address"
loop: "{{ ipv6_addresses }}"
when:
- item is regex("^FE80:")
- item | ipaddr('FE80::/16')
- item | ipv6
- item | upper
- name: is ipv6 documentation address ?
debug:
msg: "Entry: {{ item }} is a Documentation Address"
loop: "{{ ipv6_addresses | upper }}"
when:
- item is regex("^2001:DB8:")
- item | ipaddr('2001:DB8::/32')
- item | ipv6
- item | upper
- name: is ipv6 ula address ?
debug:
msg: "Entry: {{ item }} is a Unique Local Address"
loop: "{{ ipv6_addresses | upper }}"
when:
- item is regex("^FD[0-9A-F]?[0-9A-F]?:")
- item | ipaddr('FD00::/8')
- item | ipv6
- item | upper
- name: is ipv6 gua address ?
debug:
msg: "Entry: {{ item }} is a Global Unicast Address"
loop: "{{ ipv6_addresses | upper }}"
when:
- item is regex("^[2-3][0-9A-F]?[0-9A-F]?[0-9A-F]?:")
- item | ipaddr('2000::/3')
- item | ipv6
- item | upper
- name: is ipv6 gua address ?
debug:
msg: "Entry: {{ item }} is a Global Unicast Address"
loop: "{{ ipv6_addresses | upper }}"
when:
- item | ipaddr('public')
- item | upper
- name: is ipv6 private address ?
debug:
msg: "Entry: {{ item }} is a private IPv6 Address"
loop: "{{ ipv6_addresses | upper }}"
when:
- item | ipaddr('private')
- item | upper