blob: 9d6713530ae1b4e1238d961713d93be9c7e67d05 (
plain)
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
- debug: msg="START ios cli/ios_bgp.yaml on connection={{ ansible_connection }}"
- name: Clear existing BGP config
ios_bgp:
operation: delete
ignore_errors: yes
- block:
- name: Add fake config with 'bgp' string
ios_config:
match: none
replace: block
lines:
- "no ip access-list extended BGP_ACL"
- "ip access-list extended BGP_ACL"
- "permit tcp any any eq bgp"
- name: Try delete fake bgp config
register: result
ios_bgp:
operation: delete
- assert:
that:
- 'result.changed == false'
- name: Clean fake config with 'bgp' string
ios_config:
match: none
replace: block
lines:
- "no ip access-list extended BGP_ACL"
- name: Add fake bgp-like config
ios_config:
match: none
replace: block
lines:
- "no ip access-list extended BGP_ACL_2"
- "ip access-list extended BGP_ACL_2"
- "remark router bgp 64496"
- "remark neighbor 192.0.2.10 remote-as 64496"
- "remark neighbor 192.0.2.10 shutdown"
- "remark address-family ipv4"
- "remark neighbor 192.0.2.10 activate"
- "remark exit-address-family"
- "permit tcp any any eq bgp"
- name: Try delete fake bgp-like config
register: result
ios_bgp:
operation: delete
- assert:
that:
- 'result.changed == false'
- name: Clean fake bgp-like config
ios_config:
match: none
replace: block
lines:
- "no ip access-list extended BGP_ACL_2"
- name: Configure BGP with AS 64496 and a router-id
ios_bgp: &config
operation: merge
config:
bgp_as: 64496
router_id: 192.0.2.2
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'bgp router-id 192.0.2.2' in result.commands"
- name: Configure BGP with AS 64496 and a router-id (idempotent)
ios_bgp: *config
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure BGP neighbors
ios_bgp: &nbr
operation: merge
config:
bgp_as: 64496
neighbors:
- neighbor: 192.0.2.10
remote_as: 64496
password: ansible
description: IBGP_NBR_1
ebgp_multihop: 100
timers:
keepalive: 300
holdtime: 360
min_neighbor_holdtime: 360
- neighbor: 192.0.2.15
remote_as: 64496
description: IBGP_NBR_2
ebgp_multihop: 150
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'neighbor 192.0.2.10 remote-as 64496' in result.commands"
- "'neighbor 192.0.2.10 description IBGP_NBR_1' in result.commands"
- "'neighbor 192.0.2.10 ebgp-multihop 100' in result.commands"
- "'neighbor 192.0.2.10 timers 300 360 360' in result.commands"
- "'neighbor 192.0.2.15 remote-as 64496' in result.commands"
- "'neighbor 192.0.2.15 description IBGP_NBR_2' in result.commands"
- "'neighbor 192.0.2.15 ebgp-multihop 150' in result.commands"
- name: Configure BGP neighbors (idempotent)
ios_bgp: *nbr
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure BGP neighbors with operation replace
ios_bgp: &nbr_rplc
operation: replace
config:
bgp_as: 64496
neighbors:
- neighbor: 192.0.2.15
remote_as: 64496
description: IBGP_NBR_2
ebgp_multihop: 150
- neighbor: 203.0.113.10
remote_as: 64511
description: EBGP_NBR_1
local_as: 64497
- neighbor: 10.10.20.20
remote_as: 65012
description: BGP_NBR_2
ebgp_multihop: 100
register: result
- assert:
that:
- 'result.changed == true'
- "'neighbor 203.0.113.10 remote-as 64511' in result.commands"
- "'neighbor 203.0.113.10 description EBGP_NBR_1' in result.commands"
- "'neighbor 203.0.113.10 local-as 64497' in result.commands"
- "'neighbor 10.10.20.20 remote-as 65012' in result.commands"
- "'neighbor 10.10.20.20 description BGP_NBR_2' in result.commands"
- "'no neighbor 192.0.2.10' in result.commands"
- name: Configure BGP neighbors with operation replace (idempotent)
ios_bgp: *nbr_rplc
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure root-level networks for BGP
ios_bgp: &net
operation: merge
config:
bgp_as: 64496
networks:
- prefix: 203.0.113.0
masklen: 27
route_map: RMAP_1
- prefix: 203.0.113.32
masklen: 27
route_map: RMAP_2
register: result
- assert:
that:
- 'result.changed == True'
- "'router bgp 64496' in result.commands"
- "'network 203.0.113.0 mask 255.255.255.224 route-map RMAP_1' in result.commands"
- "'network 203.0.113.32 mask 255.255.255.224 route-map RMAP_2' in result.commands"
- name: Configure root-level networks for BGP (idempotent)
ios_bgp: *net
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure root-level networks for BGP with operation replace
ios_bgp: &net_rplc
operation: replace
config:
bgp_as: 64496
networks:
- prefix: 203.0.113.0
masklen: 27
route_map: RMAP_1
- prefix: 198.51.100.16
masklen: 28
register: result
- assert:
that:
- 'result.changed == True'
- "'router bgp 64496' in result.commands"
- "'network 198.51.100.16 mask 255.255.255.240' in result.commands"
- "'no network 203.0.113.32 mask 255.255.255.224 route-map RMAP_2' in result.commands"
- name: Configure root-level networks for BGP with operation replace (idempotent)
ios_bgp: *net_rplc
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure BGP neighbors under address family mode
ios_bgp: &af_nbr
operation: merge
config:
bgp_as: 64496
address_family:
- afi: ipv4
safi: unicast
neighbors:
- neighbor: 203.0.113.10
activate: yes
maximum_prefix: 250
advertisement_interval: 120
- neighbor: 192.0.2.15
activate: yes
route_reflector_client: True
- neighbor: 10.10.20.20
activate: yes
prefix_list_in: incoming-prefixes
prefix_list_out: outgoing-prefixes
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'address-family ipv4' in result.commands"
- "'neighbor 203.0.113.10 activate' in result.commands"
- "'neighbor 203.0.113.10 maximum-prefix 250' in result.commands"
- "'neighbor 203.0.113.10 advertisement-interval 120' in result.commands"
- "'neighbor 192.0.2.15 activate' in result.commands"
- "'neighbor 192.0.2.15 route-reflector-client' in result.commands"
- "'neighbor 10.10.20.20 activate' in result.commands"
- "'neighbor 10.10.20.20 prefix-list incoming-prefixes in' in result.commands"
- "'neighbor 10.10.20.20 prefix-list outgoing-prefixes out' in result.commands"
- name: Configure BGP neighbors under address family mode (idempotent)
ios_bgp: *af_nbr
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure networks under address family
ios_bgp: &af_net
operation: merge
config:
bgp_as: 64496
address_family:
- afi: ipv4
safi: multicast
networks:
- prefix: 198.51.100.48
masklen: 28
route_map: RMAP_1
- prefix: 192.0.2.64
masklen: 27
- prefix: 203.0.113.160
masklen: 27
route_map: RMAP_2
- afi: ipv4
safi: unicast
networks:
- prefix: 198.51.100.64
masklen: 28
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'address-family ipv4 multicast' in result.commands"
- "'network 198.51.100.48 mask 255.255.255.240 route-map RMAP_1' in result.commands"
- "'network 192.0.2.64 mask 255.255.255.224' in result.commands"
- "'network 203.0.113.160 mask 255.255.255.224 route-map RMAP_2' in result.commands"
- "'exit-address-family' in result.commands"
- "'address-family ipv4' in result.commands"
- "'network 198.51.100.64 mask 255.255.255.240' in result.commands"
- "'exit-address-family' in result.commands"
- name: Configure networks under address family (idempotent)
ios_bgp: *af_net
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure networks under address family with operation replace
ios_bgp: &af_net_rplc
operation: replace
config:
bgp_as: 64496
address_family:
- afi: ipv4
safi: multicast
networks:
- prefix: 198.51.100.80
masklen: 28
- prefix: 192.0.2.64
masklen: 27
- prefix: 203.0.113.192
masklen: 27
- afi: ipv4
safi: unicast
networks:
- prefix: 198.51.100.64
masklen: 28
register: result
- assert:
that:
- 'result.changed == true'
- '"router bgp 64496" in result.commands'
- '"address-family ipv4 multicast" in result.commands'
- '"network 198.51.100.80 mask 255.255.255.240" in result.commands'
- '"network 203.0.113.192 mask 255.255.255.224" in result.commands'
- '"no network 198.51.100.48 mask 255.255.255.240 route-map RMAP_1" in result.commands'
- '"no network 203.0.113.160 mask 255.255.255.224 route-map RMAP_2" in result.commands'
- '"exit-address-family" in result.commands'
- name: Configure networks under address family with operation replace (idempotent)
ios_bgp: *af_net_rplc
register: result
- assert:
that:
- 'result.changed == false'
- name: Configure redistribute information under address family mode
ios_bgp: &af_rdr
operation: merge
config:
bgp_as: 64496
address_family:
- afi: ipv4
safi: multicast
redistribute:
- protocol: ospf
id: 112
metric: 64
- protocol: eigrp
id: 233
metric: 256
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'address-family ipv4 multicast' in result.commands"
- "'redistribute ospf 112 metric 64' in result.commands"
- "'redistribute eigrp 233 metric 256' in result.commands"
- "'exit-address-family' in result.commands"
- name: Configure redistribute information under address family mode (idempotent)
ios_bgp: *af_rdr
register: result
- assert:
that:
- 'result.changed == false'
- name: Get the IOS version
ios_facts:
gather_subset: all
- name: Configure redistribute information under address family mode with operation replace
ios_bgp: &af_rdr_rplc
operation: replace
config:
bgp_as: 64496
address_family:
- afi: ipv4
safi: multicast
redistribute:
- protocol: ospf
id: 112
metric: 64
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64496' in result.commands"
- "'address-family ipv4 multicast' in result.commands"
- "'no redistribute eigrp 233' in result.commands"
- "'exit-address-family' in result.commands"
- name: Configure redistribute information under address family mode with operation replace (idempotent)
ios_bgp: *af_rdr_rplc
register: result
when: ansible_net_version != "15.6(2)T"
- assert:
that:
- 'result.changed == false'
when: ansible_net_version != "15.6(2)T"
- name: Override all the exisiting BGP config
ios_bgp:
operation: override
config:
bgp_as: 64497
router_id: 192.0.2.10
log_neighbor_changes: True
register: result
- assert:
that:
- 'result.changed == true'
- "'no router bgp 64496' in result.commands"
- "'router bgp 64497' in result.commands"
- "'bgp router-id 192.0.2.10' in result.commands"
- "'bgp log-neighbor-changes' in result.commands"
- name: "Configure BGP neighbors with classful boundary"
ios_bgp: &classful
config:
bgp_as: 64497
log_neighbor_changes: true
networks:
- prefix: 198.51.100.0
masklen: 23
- prefix: 201.0.113.32
masklen: 24
operation: merge
register: result
- assert:
that:
- 'result.changed == true'
- "'router bgp 64497' in result.commands"
- "'network 198.51.100.0 mask 255.255.254.0' in result.commands"
- "'network 201.0.113.32' in result.commands"
- name: Configure BGP neighbors with classful boundary (idempotent)
ios_bgp: *classful
register: result
- assert:
that:
- 'result.changed == false'
always:
- name: Teardown
ios_bgp: &rm
operation: delete
register: result
- assert:
that:
- 'result.changed == true'
- "'no router bgp 64497' in result.commands"
- name: Teardown again (idempotent)
ios_bgp: *rm
register: result
- assert:
that:
- 'result.changed == false'
- debug: msg="END ios cli/ios_bgp.yaml on connection={{ ansible_connection }}"
|