/
main.yml
169 lines (146 loc) · 4.1 KB
/
main.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Test code for the Meraki modules
# Copyright: (c) 2018, Kevin Breit (@kbreit)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
- name: Create appliance network
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
timezone: America/Chicago
type: appliance
delegate_to: localhost
register: net
- set_fact:
net_id: '{{net.data.id}}'
- name: Initialize static route id list
set_fact:
route_ids: []
- name: Create static_route
meraki_static_route:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
name: Test Route
subnet: 192.0.1.0/24
gateway_ip: 192.168.128.1
delegate_to: localhost
register: create_route
- set_fact:
route_ids: "{{ route_ids + [create_route.data.id] }}"
- name: Create second static_route
meraki_static_route:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
name: Test Route 2
subnet: 192.0.2.0/24
gateway_ip: 192.168.128.1
delegate_to: localhost
register: second_create
- set_fact:
route_ids: "{{ route_ids + [second_create.data.id] }}"
- assert:
that:
- create_route.changed == True
- create_route.data.id is defined
- name: Update static route
meraki_static_route:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
route_id: '{{create_route.data.id}}'
subnet: 192.0.3.0/24
enabled: yes
delegate_to: localhost
register: update
- assert:
that:
- update.data.subnet == "192.0.3.0/24"
- name: Query static routes
meraki_static_route:
auth_key: '{{auth_key}}'
state: query
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
delegate_to: localhost
register: query_all
- debug:
var: query_all
- assert:
that:
- query_all.data | length >= 2
- name: Update static route with idempotency
meraki_static_route:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
route_id: '{{create_route.data.id}}'
name: Test Route
gateway_ip: 192.168.128.1
subnet: 192.0.3.0/24
enabled: yes
delegate_to: localhost
register: update_idempotent
- assert:
that:
- update_idempotent.changed == False
- name: Update static route with fixed IP assignment and reservation
meraki_static_route:
auth_key: '{{auth_key}}'
state: present
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
route_id: '{{create_route.data.id}}'
fixed_ip_assignments:
- mac: aa:bb:cc:dd:ee:ff
ip: 192.0.3.11
name: WebServer
reserved_ip_ranges:
- start: 192.168.3.2
end: 192.168.3.10
comment: Printers
delegate_to: localhost
register: fixed_ip
- debug:
var: fixed_ip
- assert:
that:
- fixed_ip.data.fixedIpAssignments | length == 1
- fixed_ip.data.reservedIpRanges | length == 1
- name: Query single static route
meraki_static_route:
auth_key: '{{auth_key}}'
state: query
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
route_id: '{{create_route.data.id}}'
delegate_to: localhost
register: query_one
- assert:
that:
- query_one.data.name == "Test Route"
- name: Delete static routes
meraki_static_route:
auth_key: '{{auth_key}}'
state: absent
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
route_id: '{{item}}'
delegate_to: localhost
loop: '{{route_ids}}'
register: delete_all
always:
- name: Delete appliance network
meraki_network:
auth_key: '{{ auth_key }}'
state: absent
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
delegate_to: localhost