forked from mwallco/f5_ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf5_initial_setup.yml
288 lines (254 loc) · 10.5 KB
/
f5_initial_setup.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/ansible-playbook
---
#
# Copyright (c) 2016 World Wide Technology, Inc.
# All rights reserved.
#
# author: Mark Wall World Wide Technology
# short_description: Automation of F5 Initial Setup
# description: Importing configuration via CSV files to automate initial configuration of F5.
# This playbook will read a CSV file and perform initial F5 setup steps leaving a
# running active/standby pair.
#
- name: F5 Setup
hosts: localhost
connection: local
gather_facts: no
vars:
setup_user: "admin"
setup_pass: "admin"
tasks:
- name: Get facts from CSV file
csv_to_facts:
src: ./files/f5_initial_setup.csv
- name: Change Local Device Name A
icontrol_install_config:
method: "_post_"
uri: "/mgmt/tm/cm/device"
body: '{"command":"mv","name":"bigip1","target":"{{item.hostname}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Change Hostname for Device A
icontrol_install_config:
uri: "/mgmt/tm/sys/globalSettings"
method: PATCH
body: '{"hostname":"{{item.hostname}}","guiSetup":"disabled"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "yes"
- name: Change Hostname for Device B
icontrol_install_config:
uri: "/mgmt/tm/sys/globalSettings"
method: PATCH
body: "{'hostname':'{{item.hostname}}','guiSetup':'disabled'}"
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "no"
- name: Create LACP Trunk
icontrol_install_config:
uri: "/mgmt/tm/net/trunk"
body: '{"name":"{{item.trunk}}","lacp":"enabled","lacpMode":"active","lacpTimeout":"short","interfaces":["{{item.trunk_int_1}}","{{item.trunk_int_2}}"]}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create VLAN Internal
icontrol_install_config:
uri: "/mgmt/tm/net/vlan"
body: '{"name":"{{item.vlan_int}}","tag":"{{item.vlan_int_tag}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create VLAN External
icontrol_install_config:
uri: "/mgmt/tm/net/vlan"
body: '{"name":"{{item.vlan_ext}}","tag":"{{item.vlan_ext_tag}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create VLAN HA
icontrol_install_config:
uri: "/mgmt/tm/net/vlan"
body: '{"name":"{{item.vlan_ha}}","tag":"{{item.vlan_ha_tag}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Assign VLAN Internal to Interface
icontrol_install_config:
uri: "/mgmt/tm/net/vlan/~Common~{{item.vlan_int}}/interfaces"
body: '{"name":"{{item.trunk}}","tagged":true}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Assign VLAN External to Interface
icontrol_install_config:
uri: "/mgmt/tm/net/vlan/~Common~{{item.vlan_ext}}/interfaces"
body: '{"name":"{{item.trunk}}","tagged":true}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Assign VLAN HA to Interface
icontrol_install_config:
uri: "/mgmt/tm/net/vlan/~Common~{{item.vlan_ha}}/interfaces"
body: '{"name":"{{item.trunk}}","tagged":true}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Self IP External
icontrol_install_config:
uri: "/mgmt/tm/net/self"
body: '{"name":"{{item.vlan_ext_selfip}}","address":"{{item.vlan_ext_selfip}}{{item.vlan_ext_selfmask}}","vlan":"/Common/{{item.vlan_ext}}","floating":"disabled","trafficGroup":"/Common/traffic-group-local-only"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Self IP External Float
icontrol_install_config:
uri: "/mgmt/tm/net/self"
body: '{"name":"{{item.vlan_ext_float}}","address":"{{item.vlan_ext_float}}{{item.vlan_ext_selfmask}}","vlan":"/Common/{{item.vlan_ext}}","floating":"enabled","trafficGroup":"/Common/traffic-group-1"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Self IP Internal
icontrol_install_config:
uri: "/mgmt/tm/net/self"
body: '{"name":"{{item.vlan_int_selfip}}","address":"{{item.vlan_int_selfip}}{{item.vlan_int_selfmask}}","vlan":"/Common/{{item.vlan_int}}","floating":"disabled","trafficGroup":"/Common/traffic-group-local-only"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Self IP Internal Float
icontrol_install_config:
uri: "/mgmt/tm/net/self"
body: '{"name":"{{item.vlan_int_float}}","address":"{{item.vlan_int_float}}{{item.vlan_int_selfmask}}","vlan":"/Common/{{item.vlan_int}}","floating":"enabled","trafficGroup":"/Common/traffic-group-1"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Self IP HA
icontrol_install_config:
uri: "/mgmt/tm/net/self"
body: '{"name":"{{item.vlan_ha_selfip}}","address":"{{item.vlan_ha_selfip}}{{item.vlan_ha_selfmask}}","vlan":"/Common/{{item.vlan_ha}}","floating":"disabled","trafficGroup":"/Common/traffic-group-local-only"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create DNS Servers
icontrol_install_config:
uri: "/mgmt/tm/sys/dns"
method: PATCH
body: '{"nameServers":["{{item.dns_server_1}}","{{item.dns_server_2}}"],"search":["{{item.domain}}"]}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create NTP Servers
icontrol_install_config:
uri: "/mgmt/tm/sys/ntp"
method: PATCH
body: '{"servers":["{{item.ntp_server_1}}","{{item.ntp_server_2}}"],"timezone":"America/Chicago"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Create Syslog Servers
icontrol_install_config:
uri: "/mgmt/tm/sys/syslog"
method: PATCH
body: '{"remoteServers":[{"name":"remotesyslog1","host":"{{item.syslog_server}}"}]}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Change ConfigSync IP, Mirror, Unicast IP - A
icontrol_install_config:
uri: "/mgmt/tm/cm/device/~Common~{{item.hostname}}"
method: PATCH
username: "{{setup_user}}"
password: "{{setup_pass}}"
host: "{{item.appliance}}"
body: '{"configsyncIp":"{{item.vlan_ha_selfip}}","mirrorIp":"{{item.vlan_ha_selfip}}","mirrorSecondaryIp":"{{item.vlan_int_selfip}}","unicastAddress": [{"ip": "{{item.vlan_ext_selfip}}"},{"ip": "{{item.vlan_int_selfip}}"},{"ip": "{{item.appliance}}"}]}'
with_items: "{{spreadsheet}}"
when: item.primary == "yes"
- name: Change ConfigSync IP, Mirror, Unicast IP - B
icontrol_install_config:
uri: "/mgmt/tm/cm/device/~Common~{{item.hostname}}"
method: PATCH
username: "{{setup_user}}"
password: "{{setup_pass}}"
host: "{{item.appliance}}"
body: '{"configsyncIp":"{{item.vlan_ha_selfip}}","mirrorIp":"{{item.vlan_ha_selfip}}","mirrorSecondaryIp":"{{item.vlan_int_selfip}}","unicastAddress": [{"ip": "{{item.vlan_ext_selfip}}"},{"ip": "{{item.vlan_int_selfip}}"},{"ip": "{{item.appliance}}"}]}'
with_items: "{{spreadsheet}}"
when: item.primary == "no"
- name: Wait HA IP Info
wait_for:
timeout: 10
- name: Add Device to Local Trust
icontrol_install_config:
uri: "/mgmt/tm/cm/add-to-trust"
username: "{{setup_user}}"
password: "{{setup_pass}}"
host: "{{item.appliance}}"
body: '{"command":"run","name":"Root","caDevice":true,"device":"{{item.add_trust_ip}}","deviceName":"{{item.add_trust_host}}","username":"admin","password":"admin"}'
with_items: "{{spreadsheet}}"
when: item.primary == "yes"
- name: Wait Device Trust
wait_for:
timeout: 10
- name: Create SyncFailover Group
icontrol_install_config:
uri: "/mgmt/tm/cm/device-group"
body: '{"name":"SyncFail","type":"sync-failover"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
- name: Add devices to Sync Group A
icontrol_install_config:
uri: "/mgmt/tm/cm/device-group/~Common~SyncFail/devices"
body: '{"name": "{{item.hostname}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "yes"
- name: Add devices to Sync Group B
icontrol_install_config:
uri: "/mgmt/tm/cm/device-group/~Common~SyncFail/devices"
body: '{"name": "{{item.hostname}}"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "no"
- name: Initial Config Sync
icontrol_install_config:
uri: "mgmt/tm/cm/"
body: '{"command":"run","utilCmdArgs":"config-sync to-group SyncFail"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "yes"
- name: Failover B Unit
icontrol_install_config:
uri: "mgmt/tm/sys"
body: '{"command":"run","utilCmdArgs": "failover standby"}'
host: "{{item.appliance}}"
username: "{{setup_user}}"
password: "{{setup_pass}}"
with_items: "{{spreadsheet}}"
when: item.primary == "no"