Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_static_routes.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2023 Red Hat
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for ios_static_routes
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_static_routes
18 short_description: Resource module to configure static routes.
19 description: This module configures and manages the static routes on IOS platforms.
20 version_added: 1.0.0
21 author:
22 - Sagar Paul (@KB-perByte)
23 - Sumit Jaiswal (@justjais)
24 notes:
25 - Tested against Cisco IOSXE Version 17.3 on CML.
26 - This module works with connection C(network_cli).
27 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
28 - The module examples uses callback plugin (stdout_callback = yaml) to generate task
29 output in yaml format.
30 options:
31 config:
32 description: A dictionary of static route options
33 type: list
34 elements: dict
35 suboptions:
36 vrf:
37 description:
38 - IP VPN Routing/Forwarding instance name.
39 - NOTE, In case of IPV4/IPV6 VRF routing table should pre-exist before configuring.
40 - NOTE, if the vrf information is not provided then the routes shall be configured
41 under global vrf.
42 type: str
43 address_families:
44 elements: dict
45 description:
46 - Address family to use for the static routes
47 type: list
48 suboptions:
49 afi:
50 description:
51 - Top level address family indicator.
52 required: true
53 type: str
54 choices:
55 - ipv4
56 - ipv6
57 routes:
58 description: Configuring static route
59 type: list
60 elements: dict
61 suboptions:
62 dest:
63 description: Destination prefix with its subnet mask
64 type: str
65 required: true
66 topology:
67 description:
68 - Configure static route for a Topology Routing/Forwarding instance
69 - NOTE, VRF and Topology can be used together only with Multicast
70 and Topology should pre-exist before it can be used
71 type: str
72 next_hops:
73 description:
74 - next hop address or interface
75 type: list
76 elements: dict
77 suboptions:
78 forward_router_address:
79 description: Forwarding router's address
80 type: str
81 interface:
82 description: Interface for directly connected static routes
83 type: str
84 dhcp:
85 description: Default gateway obtained from DHCP
86 type: bool
87 distance_metric:
88 description: Distance metric for this route
89 type: int
90 global:
91 description: Next hop address is global
92 type: bool
93 name:
94 description: Specify name of the next hop
95 type: str
96 multicast:
97 description: multicast route
98 type: bool
99 unicast:
100 description: unicast route (ipv6 specific)
101 type: bool
102 permanent:
103 description: permanent route
104 type: bool
105 tag:
106 description:
107 - Set tag for this route
108 - Refer to vendor documentation for valid values.
109 type: int
110 track:
111 description:
112 - Install route depending on tracked item with tracked object
113 number.
114 - Tracking does not support multicast
115 - Refer to vendor documentation for valid values.
116 type: int
117 running_config:
118 description:
119 - This option is used only with state I(parsed).
120 - The value of this option should be the output received from the IOS
121 device by executing the command B(show running-config | include ip route|ipv6 route).
122 - The state I(parsed) reads the configuration from C(running_config)
123 option and transforms it into Ansible structured data as per the
124 resource module's argspec and the value is then returned in the
125 I(parsed) key within the result.
126 type: str
127 state:
128 description:
129 - The state the configuration should be left in
130 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
131 on the device.
132 - The state I(rendered) will transform the configuration in C(config) option to
133 platform specific CLI commands which will be returned in the I(rendered) key
134 within the result. For state I(rendered) active connection to remote host is
135 not required.
136 - The state I(gathered) will fetch the running configuration from device and transform
137 it into structured data in the format as per the resource module argspec and
138 the value is returned in the I(gathered) key within the result.
139 - The state I(parsed) reads the configuration from C(running_config) option and
140 transforms it into JSON format as per the resource module parameters and the
141 value is returned in the I(parsed) key within the result. The value of C(running_config)
142 option should be the same format as the output of command I(show running-config
143 | include ip route|ipv6 route) executed on device. For state I(parsed) active
144 connection to remote host is not required.
145 type: str
146 choices:
147 - merged
148 - replaced
149 - overridden
150 - deleted
151 - gathered
152 - rendered
153 - parsed
154 default: merged
155 """
156
157 EXAMPLES = """
158 # Using merged
159
160 # Before state:
161 # -------------
162 #
163 # vios#show running-config | include ip route|ipv6 route
164
165 - name: Merge provided configuration with device configuration
166 cisco.ios.ios_static_routes:
167 config:
168 - vrf: blue
169 address_families:
170 - afi: ipv4
171 routes:
172 - dest: 192.0.2.0/24
173 next_hops:
174 - forward_router_address: 192.0.2.1
175 name: merged_blue
176 tag: 50
177 track: 150
178 - address_families:
179 - afi: ipv4
180 routes:
181 - dest: 198.51.100.0/24
182 next_hops:
183 - forward_router_address: 198.51.101.1
184 name: merged_route_1
185 distance_metric: 110
186 tag: 40
187 multicast: true
188 - forward_router_address: 198.51.101.2
189 name: merged_route_2
190 distance_metric: 30
191 - forward_router_address: 198.51.101.3
192 name: merged_route_3
193 - afi: ipv6
194 routes:
195 - dest: 2001:DB8:0:3::/64
196 next_hops:
197 - forward_router_address: 2001:DB8:0:3::2
198 name: merged_v6
199 tag: 105
200 state: merged
201
202 # Task Output
203 # -----------
204 #
205 # before:
206 # - {}
207 # commands:
208 # - ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
209 # - ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
210 # - ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
211 # - ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
212 # - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
213 # after:
214 # - address_families:
215 # - afi: ipv4
216 # routes:
217 # - dest: 198.51.100.0/24
218 # next_hops:
219 # - forward_router_address: 198.51.101.3
220 # name: merged_route_3
221 # - distance_metric: 30
222 # forward_router_address: 198.51.101.2
223 # name: merged_route_2
224 # - distance_metric: 110
225 # forward_router_address: 198.51.101.1
226 # multicast: true
227 # name: merged_route_1
228 # tag: 40
229 # - afi: ipv6
230 # routes:
231 # - dest: 2001:DB8:0:3::/64
232 # next_hops:
233 # - forward_router_address: 2001:DB8:0:3::2
234 # name: merged_v6
235 # tag: 105
236 # - address_families:
237 # - afi: ipv4
238 # routes:
239 # - dest: 192.0.2.0/24
240 # next_hops:
241 # - forward_router_address: 192.0.2.1
242 # name: merged_blue
243 # tag: 50
244 # track: 150
245 # vrf: blue
246
247 # After state:
248 # ------------
249 #
250 # vios#show running-config | include ip route|ipv6 route
251 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
252 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
253 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
254 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
255 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
256
257 # Using replaced
258
259 # Before state:
260 # -------------
261 #
262 # vios#show running-config | include ip route|ipv6 route
263 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
264 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
265 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
266 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name merged_route_1 multicast
267 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
268
269 - name: Replace provided configuration with device configuration
270 cisco.ios.ios_static_routes:
271 config:
272 - address_families:
273 - afi: ipv4
274 routes:
275 - dest: 198.51.100.0/24
276 next_hops:
277 - forward_router_address: 198.51.101.1
278 name: replaced_route
279 distance_metric: 175
280 tag: 70
281 multicast: true
282 state: replaced
283
284 # Task Output
285 # -----------
286 #
287 # before:
288 # - address_families:
289 # - afi: ipv4
290 # routes:
291 # - dest: 198.51.100.0/24
292 # next_hops:
293 # - forward_router_address: 198.51.101.3
294 # name: merged_route_3
295 # - distance_metric: 30
296 # forward_router_address: 198.51.101.2
297 # name: merged_route_2
298 # - distance_metric: 110
299 # forward_router_address: 198.51.101.1
300 # multicast: true
301 # name: merged_route_1
302 # tag: 40
303 # - afi: ipv6
304 # routes:
305 # - dest: 2001:DB8:0:3::/64
306 # next_hops:
307 # - forward_router_address: 2001:DB8:0:3::2
308 # name: merged_v6
309 # tag: 105
310 # - address_families:
311 # - afi: ipv4
312 # routes:
313 # - dest: 192.0.2.0/24
314 # next_hops:
315 # - forward_router_address: 192.0.2.1
316 # name: merged_blue
317 # tag: 50
318 # track: 150
319 # vrf: blue
320 # commands:
321 # - ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
322 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name merged_route_3
323 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name merged_route_2
324 # after:
325 # - address_families:
326 # - afi: ipv4
327 # routes:
328 # - dest: 198.51.100.0/24
329 # next_hops:
330 # - distance_metric: 175
331 # forward_router_address: 198.51.101.1
332 # multicast: true
333 # name: replaced_route
334 # tag: 70
335 # - afi: ipv6
336 # routes:
337 # - dest: 2001:DB8:0:3::/64
338 # next_hops:
339 # - forward_router_address: 2001:DB8:0:3::2
340 # name: merged_v6
341 # tag: 105
342 # - address_families:
343 # - afi: ipv4
344 # routes:
345 # - dest: 192.0.2.0/24
346 # next_hops:
347 # - forward_router_address: 192.0.2.1
348 # name: merged_blue
349 # tag: 50
350 # track: 150
351 # vrf: blue
352
353 # After state:
354 # ------------
355 #
356 # vios#show running-config | include ip route|ipv6 route
357 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
358 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
359 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
360
361 # Using overridden
362
363 # Before state:
364 # -------------
365 #
366 # vios#show running-config | include ip route|ipv6 route
367 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name merged_blue track 150
368 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
369 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
370
371 - name: Override provided configuration with device configuration
372 cisco.ios.ios_static_routes:
373 config:
374 - vrf: blue
375 address_families:
376 - afi: ipv4
377 routes:
378 - dest: 192.0.2.0/24
379 next_hops:
380 - forward_router_address: 192.0.2.1
381 name: override_vrf
382 tag: 50
383 track: 150
384 state: overridden
385
386 # Task Output
387 # -----------
388 #
389 # before:
390 # - address_families:
391 # - afi: ipv4
392 # routes:
393 # - dest: 198.51.100.0/24
394 # next_hops:
395 # - distance_metric: 175
396 # forward_router_address: 198.51.101.1
397 # multicast: true
398 # name: replaced_route
399 # tag: 70
400 # - afi: ipv6
401 # routes:
402 # - dest: 2001:DB8:0:3::/64
403 # next_hops:
404 # - forward_router_address: 2001:DB8:0:3::2
405 # name: merged_v6
406 # tag: 105
407 # - address_families:
408 # - afi: ipv4
409 # routes:
410 # - dest: 192.0.2.0/24
411 # next_hops:
412 # - forward_router_address: 192.0.2.1
413 # name: merged_blue
414 # tag: 50
415 # track: 150
416 # vrf: blue
417 # commands:
418 # - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name override_vrf track 150
419 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 175 tag 70 name replaced_route multicast
420 # - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name merged_v6
421 # after:
422 # - address_families:
423 # - afi: ipv4
424 # routes:
425 # - dest: 192.0.2.0/24
426 # next_hops:
427 # - forward_router_address: 192.0.2.1
428 # name: override_vrf
429 # tag: 50
430 # track: 150
431 # vrf: blue
432
433 # After state:
434 # ------------
435 #
436 # vios#show running-config | include ip route|ipv6 route
437 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name override_vrf track 150
438
439 # Using deleted
440
441 # Before state:
442 # -------------
443 # vios#show running-config | include ip route|ipv6 route
444 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
445 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
446 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
447 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
448 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
449
450 - name: Delete the exact static routes, with all the static routes explicitly mentioned in want
451 cisco.ios.ios_static_routes:
452 config:
453 - vrf: blue
454 address_families:
455 - afi: ipv4
456 routes:
457 - dest: 192.0.2.0/24
458 next_hops:
459 - forward_router_address: 192.0.2.1
460 name: test_vrf
461 tag: 50
462 track: 150
463 - address_families:
464 - afi: ipv4
465 routes:
466 - dest: 198.51.100.0/24
467 next_hops:
468 - forward_router_address: 198.51.101.1
469 name: route_1
470 distance_metric: 110
471 tag: 40
472 multicast: true
473 - forward_router_address: 198.51.101.2
474 name: route_2
475 distance_metric: 30
476 - forward_router_address: 198.51.101.3
477 name: route_3
478 - afi: ipv6
479 routes:
480 - dest: 2001:DB8:0:3::/64
481 next_hops:
482 - forward_router_address: 2001:DB8:0:3::2
483 name: test_v6
484 tag: 105
485 state: deleted
486
487 # Task Output
488 # -----------
489 #
490 # before:
491 # - address_families:
492 # - afi: ipv4
493 # routes:
494 # - dest: 198.51.100.0/24
495 # next_hops:
496 # - forward_router_address: 198.51.101.3
497 # name: route_3
498 # - distance_metric: 30
499 # forward_router_address: 198.51.101.2
500 # name: route_2
501 # - distance_metric: 110
502 # forward_router_address: 198.51.101.1
503 # multicast: true
504 # name: route_1
505 # tag: 40
506 # - afi: ipv6
507 # routes:
508 # - dest: 2001:DB8:0:3::/64
509 # next_hops:
510 # - forward_router_address: 2001:DB8:0:3::2
511 # name: test_v6
512 # tag: 105
513 # - address_families:
514 # - afi: ipv4
515 # routes:
516 # - dest: 192.0.2.0/24
517 # next_hops:
518 # - forward_router_address: 192.0.2.1
519 # name: test_vrf
520 # tag: 50
521 # track: 150
522 # vrf: blue
523 # commands:
524 # - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
525 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
526 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
527 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
528 # - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
529 # after: {}
530
531 # After state:
532 # ------------
533 #
534 # vios#show running-config | include ip route|ipv6 route
535
536 # Using deleted - delete based on specific routes
537
538 # Before state:
539 # -------------
540 #
541 # vios#show running-config | include ip route|ipv6 route
542 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
543 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
544 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
545 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
546 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
547
548 - name: Delete destination specific static routes
549 cisco.ios.ios_static_routes:
550 config:
551 - address_families:
552 - afi: ipv4
553 routes:
554 - dest: 198.51.100.0/24
555 state: deleted
556
557 # Task Output
558 # -----------
559 #
560 # before:
561 # - address_families:
562 # - afi: ipv4
563 # routes:
564 # - dest: 198.51.100.0/24
565 # next_hops:
566 # - forward_router_address: 198.51.101.3
567 # name: route_3
568 # - distance_metric: 30
569 # forward_router_address: 198.51.101.2
570 # name: route_2
571 # - distance_metric: 110
572 # forward_router_address: 198.51.101.1
573 # multicast: true
574 # name: route_1
575 # tag: 40
576 # - afi: ipv6
577 # routes:
578 # - dest: 2001:DB8:0:3::/64
579 # next_hops:
580 # - forward_router_address: 2001:DB8:0:3::2
581 # name: test_v6
582 # tag: 105
583 # - address_families:
584 # - afi: ipv4
585 # routes:
586 # - dest: 192.0.2.0/24
587 # next_hops:
588 # - forward_router_address: 192.0.2.1
589 # name: test_vrf
590 # tag: 50
591 # track: 150
592 # vrf: blue
593 # commands:
594 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
595 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
596 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
597 # after:
598 # - address_families:
599 # - afi: ipv6
600 # routes:
601 # - dest: 2001:DB8:0:3::/64
602 # next_hops:
603 # - forward_router_address: 2001:DB8:0:3::2
604 # name: test_v6
605 # tag: 105
606 # - address_families:
607 # - afi: ipv4
608 # routes:
609 # - dest: 192.0.2.0/24
610 # next_hops:
611 # - forward_router_address: 192.0.2.1
612 # name: test_vrf
613 # tag: 50
614 # track: 150
615 # vrf: blue
616
617 # After state:
618 # ------------
619 #
620 # vios#show running-config | include ip route|ipv6 route
621 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
622 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
623
624 # Using deleted - delete based on vrfs
625
626 # Before state:
627 # -------------
628 #
629 # vios#show running-config | include ip route|ipv6 route
630 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
631 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
632 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
633 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
634 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
635
636 - name: Delete vrf specific static routes
637 cisco.ios.ios_static_routes:
638 config:
639 - vrf: blue
640 state: deleted
641
642 # Task Output
643 # -----------
644 #
645 # before:
646 # - address_families:
647 # - afi: ipv4
648 # routes:
649 # - dest: 198.51.100.0/24
650 # next_hops:
651 # - forward_router_address: 198.51.101.3
652 # name: route_3
653 # - distance_metric: 30
654 # forward_router_address: 198.51.101.2
655 # name: route_2
656 # - distance_metric: 110
657 # forward_router_address: 198.51.101.1
658 # multicast: true
659 # name: route_1
660 # tag: 40
661 # - afi: ipv6
662 # routes:
663 # - dest: 2001:DB8:0:3::/64
664 # next_hops:
665 # - forward_router_address: 2001:DB8:0:3::2
666 # name: test_v6
667 # tag: 105
668 # - address_families:
669 # - afi: ipv4
670 # routes:
671 # - dest: 192.0.2.0/24
672 # next_hops:
673 # - forward_router_address: 192.0.2.1
674 # name: test_vrf
675 # tag: 50
676 # track: 150
677 # vrf: blue
678 # commands:
679 # - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
680 # after:
681 # - address_families:
682 # - afi: ipv4
683 # routes:
684 # - dest: 198.51.100.0/24
685 # next_hops:
686 # - forward_router_address: 198.51.101.3
687 # name: route_3
688 # - distance_metric: 30
689 # forward_router_address: 198.51.101.2
690 # name: route_2
691 # - distance_metric: 110
692 # forward_router_address: 198.51.101.1
693 # multicast: true
694 # name: route_1
695 # tag: 40
696 # - afi: ipv6
697 # routes:
698 # - dest: 2001:DB8:0:3::/64
699 # next_hops:
700 # - forward_router_address: 2001:DB8:0:3::2
701 # name: test_v6
702 # tag: 105
703
704 # After state:
705 # ------------
706 #
707 # vios#show running-config | include ip route|ipv6 route
708 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
709 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
710 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
711 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
712
713 # Using deleted - delete all
714
715 # Before state:
716 # -------------
717 #
718 # vios#show running-config | include ip route|ipv6 route
719 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
720 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
721 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
722 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
723 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
724
725 - name: Delete ALL configured static routes
726 cisco.ios.ios_static_routes:
727 state: deleted
728
729 # Task Output
730 # -----------
731 #
732 # before:
733 # - address_families:
734 # - afi: ipv4
735 # routes:
736 # - dest: 198.51.100.0/24
737 # next_hops:
738 # - forward_router_address: 198.51.101.3
739 # name: route_3
740 # - distance_metric: 30
741 # forward_router_address: 198.51.101.2
742 # name: route_2
743 # - distance_metric: 110
744 # forward_router_address: 198.51.101.1
745 # multicast: true
746 # name: route_1
747 # tag: 40
748 # - afi: ipv6
749 # routes:
750 # - dest: 2001:DB8:0:3::/64
751 # next_hops:
752 # - forward_router_address: 2001:DB8:0:3::2
753 # name: test_v6
754 # tag: 105
755 # - address_families:
756 # - afi: ipv4
757 # routes:
758 # - dest: 192.0.2.0/24
759 # next_hops:
760 # - forward_router_address: 192.0.2.1
761 # name: test_vrf
762 # tag: 50
763 # track: 150
764 # vrf: blue
765 # commands:
766 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
767 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
768 # - no ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
769 # - no ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
770 # - no ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
771 # after: {}
772
773 # After state:
774 # -------------
775 #
776 # vios#show running-config | include ip route|ipv6 route
777
778 # Using gathered
779
780 # Before state:
781 # -------------
782 #
783 # vios#show running-config | include ip route|ipv6 route
784 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
785 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
786 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
787 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
788 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
789
790 - name: Gather facts of static routes
791 cisco.ios.ios_static_routes:
792 config:
793 state: gathered
794
795 # Task Output
796 # -----------
797 #
798 # gathered:
799 # - address_families:
800 # - afi: ipv4
801 # routes:
802 # - dest: 198.51.100.0/24
803 # next_hops:
804 # - forward_router_address: 198.51.101.3
805 # name: route_3
806 # - distance_metric: 30
807 # forward_router_address: 198.51.101.2
808 # name: route_2
809 # - distance_metric: 110
810 # forward_router_address: 198.51.101.1
811 # multicast: true
812 # name: route_1
813 # tag: 40
814 # - afi: ipv6
815 # routes:
816 # - dest: 2001:DB8:0:3::/64
817 # next_hops:
818 # - forward_router_address: 2001:DB8:0:3::2
819 # name: test_v6
820 # tag: 105
821 # - address_families:
822 # - afi: ipv4
823 # routes:
824 # - dest: 192.0.2.0/24
825 # next_hops:
826 # - forward_router_address: 192.0.2.1
827 # name: test_vrf
828 # tag: 50
829 # track: 150
830 # vrf: blue
831
832 # Using rendered
833
834 - name: Render the commands for provided configuration
835 cisco.ios.ios_static_routes:
836 config:
837 - vrf: blue
838 address_families:
839 - afi: ipv4
840 routes:
841 - dest: 192.0.2.0/24
842 next_hops:
843 - forward_router_address: 192.0.2.1
844 name: test_vrf
845 tag: 50
846 track: 150
847 - address_families:
848 - afi: ipv4
849 routes:
850 - dest: 198.51.100.0/24
851 next_hops:
852 - forward_router_address: 198.51.101.1
853 name: route_1
854 distance_metric: 110
855 tag: 40
856 multicast: true
857 - forward_router_address: 198.51.101.2
858 name: route_2
859 distance_metric: 30
860 - forward_router_address: 198.51.101.3
861 name: route_3
862 - afi: ipv6
863 routes:
864 - dest: 2001:DB8:0:3::/64
865 next_hops:
866 - forward_router_address: 2001:DB8:0:3::2
867 name: test_v6
868 tag: 105
869 state: rendered
870
871 # Task Output
872 # -----------
873 #
874 # rendered:
875 # - ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
876 # - ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
877 # - ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
878 # - ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
879 # - ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
880
881 # Using parsed
882
883 # File: parsed.cfg
884 # ----------------
885 #
886 # ip route vrf blue 192.0.2.0 255.255.255.0 192.0.2.1 tag 50 name test_vrf track 150
887 # ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
888 # ip route 198.51.100.0 255.255.255.0 198.51.101.2 30 name route_2
889 # ip route 198.51.100.0 255.255.255.0 198.51.101.1 110 tag 40 name route_1 multicast
890 # ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
891
892 - name: Parse the provided configuration
893 cisco.ios.ios_static_routes:
894 running_config: "{{ lookup('file', 'parsed.cfg') }}"
895 state: parsed
896
897 # Task Output
898 # -----------
899 #
900 # parsed:
901 # - address_families:
902 # - afi: ipv4
903 # routes:
904 # - dest: 198.51.100.0/24
905 # next_hops:
906 # - forward_router_address: 198.51.101.3
907 # name: route_3
908 # - distance_metric: 30
909 # forward_router_address: 198.51.101.2
910 # name: route_2
911 # - distance_metric: 110
912 # forward_router_address: 198.51.101.1
913 # multicast: true
914 # name: route_1
915 # tag: 40
916 # - afi: ipv6
917 # routes:
918 # - dest: 2001:DB8:0:3::/64
919 # next_hops:
920 # - forward_router_address: 2001:DB8:0:3::2
921 # name: test_v6
922 # tag: 105
923 # - address_families:
924 # - afi: ipv4
925 # routes:
926 # - dest: 192.0.2.0/24
927 # next_hops:
928 # - forward_router_address: 192.0.2.1
929 # name: test_vrf
930 # tag: 50
931 # track: 150
932 # vrf: blue
933 """
934
935 RETURN = """
936 before:
937 description: The configuration as structured data prior to module invocation.
938 returned: always
939 type: list
940 sample: The configuration returned will always be in the same format of the parameters above.
941 after:
942 description: The configuration as structured data after module completion.
943 returned: when changed
944 type: list
945 sample: The configuration returned will always be in the same format of the parameters above.
946 commands:
947 description: The set of commands pushed to the remote device
948 returned: always
949 type: list
950 sample: ['ip route vrf test 172.31.10.0 255.255.255.0 10.10.10.2 name new_test multicast']
951 rendered:
952 description: The set of CLI commands generated from the value in C(config) option
953 returned: When C(state) is I(rendered)
954 type: list
955 sample:
956 - ip route 198.51.100.0 255.255.255.0 198.51.101.3 name route_3
957 - ipv6 route 2001:DB8:0:3::/64 2001:DB8:0:3::2 tag 105 name test_v6
958 gathered:
959 description:
960 - The configuration as structured data transformed for the running configuration
961 fetched from remote host
962 returned: When C(state) is I(gathered)
963 type: list
964 sample: >
965 The configuration returned will always be in the same format
966 of the parameters above.
967 parsed:
968 description:
969 - The configuration as structured data transformed for the value of
970 C(running_config) option
971 returned: When C(state) is I(parsed)
972 type: list
973 sample: >
974 The configuration returned will always be in the same format
975 of the parameters above.
976 """
977
978
979 from ansible.module_utils.basic import AnsibleModule
980
981 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.static_routes.static_routes import (
982 Static_routesArgs,
983 )
984 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.static_routes.static_routes import (
985 Static_routes,
986 )
987
988
989 def main():
990 """
991 Main entry point for module execution
992
993 :returns: the result form module invocation
994 """
995 module = AnsibleModule(
996 argument_spec=Static_routesArgs.argument_spec,
997 mutually_exclusive=[["config", "running_config"]],
998 required_if=[
999 ["state", "merged", ["config"]],
1000 ["state", "replaced", ["config"]],
1001 ["state", "overridden", ["config"]],
1002 ["state", "rendered", ["config"]],
1003 ["state", "parsed", ["running_config"]],
1004 ],
1005 supports_check_mode=True,
1006 )
1007
1008 result = Static_routes(module).execute_module()
1009 module.exit_json(**result)
1010
1011
1012 if __name__ == "__main__":
1013 main()