Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/modules/iosxr_static_routes.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2019 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 # WARNING #
9 #############################################
10 #
11 # This file is auto generated by the resource
12 # module builder playbook.
13 #
14 # Do not edit this file manually.
15 #
16 # Changes to this file will be over written
17 # by the resource module builder.
18 #
19 # Changes should be made in the model used to
20 # generate this file or in the resource module
21 # builder template.
22 #
23 #############################################
24
25 """
26 The module file for iosxr_static_routes
27 """
28
29 from __future__ import absolute_import, division, print_function
30
31
32 __metaclass__ = type
33
34
35 DOCUMENTATION = """
36 module: iosxr_static_routes
37 short_description: Resource module to configure static routes.
38 description:
39 - This module manages static routes on devices running Cisco IOS-XR.
40 version_added: 1.0.0
41 author: Nilashish Chakraborty (@NilashishC)
42 options:
43 running_config:
44 description:
45 - This option is used only with state I(parsed).
46 - The value of this option should be the output received from the IOS-XR device
47 by executing the command B(show running-config router static).
48 - The state I(parsed) reads the configuration from C(running_config) option and
49 transforms it into Ansible structured data as per the resource module's argspec
50 and the value is then returned in the I(parsed) key within the result.
51 type: str
52 config:
53 description: A dictionary of static route options.
54 type: list
55 elements: dict
56 suboptions:
57 vrf:
58 description:
59 - The VRF to which the static route(s) belong.
60 type: str
61 address_families:
62 description: A dictionary specifying the address family to which the static
63 route(s) belong.
64 type: list
65 elements: dict
66 suboptions:
67 afi:
68 description:
69 - Specifies the top level address family indicator.
70 type: str
71 choices:
72 - ipv4
73 - ipv6
74 required: true
75 safi:
76 description:
77 - Specifies the subsequent address family indicator.
78 type: str
79 choices:
80 - unicast
81 - multicast
82 required: true
83 routes:
84 description: A dictionary that specifies the static route configurations.
85 elements: dict
86 type: list
87 suboptions:
88 dest:
89 description:
90 - An IPv4 or IPv6 address in CIDR notation that specifies the destination
91 network for the static route.
92 type: str
93 required: true
94 next_hops:
95 description:
96 - Next hops to the specified destination.
97 type: list
98 elements: dict
99 suboptions:
100 forward_router_address:
101 description:
102 - The IP address of the next hop that can be used to reach the
103 destination network.
104 type: str
105 interface:
106 description:
107 - The interface to use to reach the destination.
108 type: str
109 dest_vrf:
110 description:
111 - The destination VRF.
112 type: str
113 admin_distance:
114 description:
115 - The administrative distance for this static route.
116 - Refer to vendor documentation for valid values.
117 type: int
118 metric:
119 description:
120 - Specifes the metric for this static route.
121 - Refer to vendor documentation for valid values.
122 type: int
123 description:
124 description:
125 - Specifies the description for this static route.
126 type: str
127 vrflabel:
128 description:
129 - Specifies the VRF label for this static route.
130 - Refer to vendor documentation for valid values.
131 type: int
132 tag:
133 description:
134 - Specifies a numeric tag for this static route.
135 - Refer to vendor documentation for valid values.
136 type: int
137 track:
138 description:
139 - Specifies the object to be tracked.
140 - This enables object tracking for static routes.
141 type: str
142 tunnel_id:
143 description:
144 - Specifies a tunnel id for the route.
145 - Refer to vendor documentation for valid values.
146 type: int
147 state:
148 description:
149 - The state the configuration should be left in.
150 type: str
151 choices:
152 - merged
153 - replaced
154 - overridden
155 - deleted
156 - gathered
157 - rendered
158 - parsed
159 default: merged
160
161 """
162 EXAMPLES = """
163
164 # Using merged
165
166 # Before state
167 # -------------
168 # RP/0/RP0/CPU0:ios#show running-config router static
169 # Sat Feb 22 07:46:30.089 UTC
170 # % No such configuration item(s)
171 #
172 - name: Merge the provided configuration with the existing running configuration
173 cisco.iosxr.iosxr_static_routes:
174 config:
175 - address_families:
176 - afi: ipv4
177 safi: unicast
178 routes:
179 - dest: 192.0.2.16/28
180 next_hops:
181 - forward_router_address: 192.0.2.10
182 interface: FastEthernet0/0/0/1
183 description: LAB
184 metric: 120
185 tag: 10
186 - interface: FastEthernet0/0/0/5
187 track: ip_sla_1
188 - dest: 192.0.2.32/28
189 next_hops:
190 - forward_router_address: 192.0.2.11
191 admin_distance: 100
192 - afi: ipv6
193 safi: unicast
194 routes:
195 - dest: '2001:db8:1000::/36'
196 next_hops:
197 - interface: FastEthernet0/0/0/7
198 description: DC
199 - interface: FastEthernet0/0/0/8
200 forward_router_address: '2001:db8:2000:2::1'
201 - vrf: DEV_SITE
202 address_families:
203 - afi: ipv4
204 safi: unicast
205 routes:
206 - dest: 192.0.2.48/28
207 next_hops:
208 - forward_router_address: 192.0.2.12
209 description: DEV
210 dest_vrf: test_1
211 - dest: 192.0.2.80/28
212 next_hops:
213 - interface: FastEthernet0/0/0/2
214 forward_router_address: 192.0.2.14
215 dest_vrf: test_1
216 track: ip_sla_2
217 vrflabel: 124
218 state: merged
219
220
221 # Task Output
222 # -----------
223 # before: []
224 # commands:
225 # - router static
226 # - address-family ipv4 unicast
227 # - 192.0.2.16/28 192.0.2.10 FastEthernet0/0/0/1 description LAB metric 120 tag 10
228 # - 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
229 # - 192.0.2.32/28 192.0.2.11 100
230 # - address-family ipv6 unicast
231 # - 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
232 # - 2001:db8:1000::/36 2001:db8:2000:2::1 FastEthernet0/0/0/8
233 # - vrf DEV_SITE
234 # - address-family ipv4 unicast
235 # - 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
236 # - 192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 track ip_sla_2 vrflabel 124
237 # after:
238 # - address_families:
239 # - afi: ipv4
240 # routes:
241 # - dest: 192.0.2.16/28
242 # next_hops:
243 # - description: LAB
244 # forward_router_address: 192.0.2.10
245 # interface: FastEthernet0/0/0/1
246 # metric: 120
247 # tag: 10
248 # - interface: FastEthernet0/0/0/5
249 # track: ip_sla_1
250 # - dest: 192.0.2.32/28
251 # next_hops:
252 # - admin_distance: 100
253 # forward_router_address: 192.0.2.11
254 # safi: unicast
255 # - afi: ipv6
256 # routes:
257 # - dest: 2001:db8:1000::/36
258 # next_hops:
259 # - description: DC
260 # interface: FastEthernet0/0/0/7
261 # - forward_router_address: 2001:db8:2000:2::1
262 # interface: FastEthernet0/0/0/8
263 # safi: unicast
264 # - address_families:
265 # - afi: ipv4
266 # routes:
267 # - dest: 192.0.2.48/28
268 # next_hops:
269 # - description: DEV
270 # dest_vrf: test_1
271 # forward_router_address: 192.0.2.12
272 # - dest: 192.0.2.80/28
273 # next_hops:
274 # - dest_vrf: test_1
275 # forward_router_address: 192.0.2.14
276 # interface: FastEthernet0/0/0/2
277 # track: ip_sla_2
278 # vrflabel: 124
279 # safi: unicast
280 # vrf: DEV_SITE
281
282
283 #
284 # After state
285 # -------------
286 # RP/0/RP0/CPU0:ios#show running-config router static
287 # Sat Feb 22 07:49:11.754 UTC
288 # router static
289 # address-family ipv4 unicast
290 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
291 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
292 # 192.0.2.32/28 192.0.2.11 100
293 # !
294 # address-family ipv6 unicast
295 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
296 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
297 # !
298 # vrf DEV_SITE
299 # address-family ipv4 unicast
300 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
301 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
302 # !
303 # !
304 # !
305
306 # Using merged to update existing static routes
307
308 # Before state
309 # -------------
310 # RP/0/RP0/CPU0:ios#show running-config router static
311 # Sat Feb 22 07:49:11.754 UTC
312 # router static
313 # address-family ipv4 unicast
314 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
315 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
316 # 192.0.2.32/28 192.0.2.11 100
317 # !
318 # address-family ipv6 unicast
319 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
320 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
321 # !
322 # vrf DEV_SITE
323 # address-family ipv4 unicast
324 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
325 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
326 # !
327 # !
328 # !
329
330 - name: Update existing static routes configuration using merged
331 cisco.iosxr.iosxr_static_routes:
332 config:
333 - vrf: DEV_SITE
334 address_families:
335 - afi: ipv4
336 safi: unicast
337 routes:
338 - dest: 192.0.2.48/28
339 next_hops:
340 - forward_router_address: 192.0.2.12
341 vrflabel: 2301
342 dest_vrf: test_1
343 - dest: 192.0.2.80/28
344 next_hops:
345 - interface: FastEthernet0/0/0/2
346 forward_router_address: 192.0.2.14
347 dest_vrf: test_1
348 description: rt_test_1
349 state: merged
350
351 # Task Output
352 # -----------
353 # before:
354 # - address_families:
355 # - afi: ipv4
356 # routes:
357 # - dest: 192.0.2.16/28
358 # next_hops:
359 # - description: LAB
360 # forward_router_address: 192.0.2.10
361 # interface: FastEthernet0/0/0/1
362 # metric: 120
363 # tag: 10
364 # - interface: FastEthernet0/0/0/5
365 # track: ip_sla_1
366 # - dest: 192.0.2.32/28
367 # next_hops:
368 # - admin_distance: 100
369 # forward_router_address: 192.0.2.11
370 # safi: unicast
371 # - afi: ipv6
372 # routes:
373 # - dest: 2001:db8:1000::/36
374 # next_hops:
375 # - description: DC
376 # interface: FastEthernet0/0/0/7
377 # - forward_router_address: 2001:db8:2000:2::1
378 # interface: FastEthernet0/0/0/8
379 # safi: unicast
380 # - address_families:
381 # - afi: ipv4
382 # routes:
383 # - dest: 192.0.2.48/28
384 # next_hops:
385 # - description: DEV
386 # dest_vrf: test_1
387 # forward_router_address: 192.0.2.12
388 # - dest: 192.0.2.80/28
389 # next_hops:
390 # - dest_vrf: test_1
391 # forward_router_address: 192.0.2.14
392 # interface: FastEthernet0/0/0/2
393 # track: ip_sla_2
394 # vrflabel: 124
395 # safi: unicast
396 # vrf: DEV_SITE
397 # commands:
398 # - router static
399 # - vrf DEV_SITE
400 # - address-family ipv4 unicast
401 # - 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV vrflabel 2301
402 # - 192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 description rt_test_1 track ip_sla_2 vrflabel 124
403 # after:
404 # - address_families:
405 # - afi: ipv4
406 # routes:
407 # - dest: 192.0.2.16/28
408 # next_hops:
409 # - description: LAB
410 # forward_router_address: 192.0.2.10
411 # interface: FastEthernet0/0/0/1
412 # metric: 120
413 # tag: 10
414 # - interface: FastEthernet0/0/0/5
415 # track: ip_sla_1
416 # - dest: 192.0.2.32/28
417 # next_hops:
418 # - admin_distance: 100
419 # forward_router_address: 192.0.2.11
420 # safi: unicast
421 # - afi: ipv6
422 # routes:
423 # - dest: 2001:db8:1000::/36
424 # next_hops:
425 # - description: DC
426 # interface: FastEthernet0/0/0/7
427 # - forward_router_address: 2001:db8:2000:2::1
428 # interface: FastEthernet0/0/0/8
429 # safi: unicast
430 # - address_families:
431 # - afi: ipv4
432 # routes:
433 # - dest: 192.0.2.48/28
434 # next_hops:
435 # - description: DEV
436 # dest_vrf: test_1
437 # forward_router_address: 192.0.2.12
438 # vrflabel: 2301
439 # - dest: 192.0.2.80/28
440 # next_hops:
441 # - description: rt_test_1
442 # dest_vrf: test_1
443 # forward_router_address: 192.0.2.14
444 # interface: FastEthernet0/0/0/2
445 # track: ip_sla_2
446 # vrflabel: 124
447 # safi: unicast
448 # vrf: DEV_SITE
449
450 # After state
451 # -------------
452 # RP/0/RP0/CPU0:ios#show running-config router static
453 # Sat Feb 22 07:49:11.754 UTC
454 # router static
455 # address-family ipv4 unicast
456 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
457 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
458 # 192.0.2.32/28 192.0.2.11 100
459 # !
460 # address-family ipv6 unicast
461 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
462 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
463 # !
464 # vrf DEV_SITE
465 # address-family ipv4 unicast
466 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV vrflabel 2301
467 # 192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 description rt_test_1 track ip_sla_2 vrflabel 124
468 # !
469 # !
470 # !
471
472 # Using replaced to replace all next hop entries for a single destination network
473
474 # Before state
475 # --------------
476
477 # RP/0/RP0/CPU0:ios#sh running-config router static
478 # Sat Feb 22 07:59:08.669 UTC
479 # router static
480 # address-family ipv4 unicast
481 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
482 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
483 # 192.0.2.32/28 192.0.2.11 100
484 # !
485 # address-family ipv6 unicast
486 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
487 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
488 # !
489 # vrf DEV_SITE
490 # address-family ipv4 unicast
491 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
492 # 192.0.2.48/28 GigabitEthernet0/0/0/1 192.0.3.24 vrflabel 2302
493 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
494 # !
495 # !
496 # !
497
498 - name: Replace device configurations of static routes with provided configurations
499 cisco.iosxr.iosxr_static_routes:
500 config:
501 - vrf: DEV_SITE
502 address_families:
503 - afi: ipv4
504 safi: unicast
505 routes:
506 - dest: 192.0.2.48/28
507 next_hops:
508 - forward_router_address: 192.0.2.15
509 interface: FastEthernet0/0/0/3
510 description: DEV_NEW
511 dest_vrf: dev_test_2
512 state: replaced
513
514 # Task Output
515 # -----------
516 # before:
517 # - address_families:
518 # - afi: ipv4
519 # routes:
520 # - dest: 0.0.0.0/0
521 # next_hops:
522 # - forward_router_address: 10.0.151.254
523 # interface: MgmtEth0
524 # - dest: 192.0.2.16/28
525 # next_hops:
526 # - description: LAB
527 # forward_router_address: 192.0.2.10
528 # interface: FastEthernet0/0/0/1
529 # metric: 120
530 # tag: 10
531 # - interface: FastEthernet0/0/0/5
532 # track: ip_sla_1
533 # - dest: 192.0.2.32/28
534 # next_hops:
535 # - admin_distance: 100
536 # forward_router_address: 192.0.2.11
537 # safi: unicast
538 # - afi: ipv6
539 # routes:
540 # - dest: 2001:db8:1000::/36
541 # next_hops:
542 # - description: DC
543 # interface: FastEthernet0/0/0/7
544 # - forward_router_address: 2001:db8:2000:2::1
545 # interface: FastEthernet0/0/0/8
546 # safi: unicast
547 # - address_families:
548 # - afi: ipv4
549 # routes:
550 # - dest: 192.0.2.48/28
551 # next_hops:
552 # - description: DEV
553 # dest_vrf: test_1
554 # forward_router_address: 192.0.2.12
555 # - forward_router_address: 192.0.3.24
556 # interface: GigabitEthernet0/0/0/1
557 # vrflabel: 2302
558 # - dest: 192.0.2.80/28
559 # next_hops:
560 # - dest_vrf: test_1
561 # forward_router_address: 192.0.2.14
562 # interface: FastEthernet0/0/0/2
563 # track: ip_sla_2
564 # vrflabel: 124
565 # safi: unicast
566 # vrf: DEV_SITE
567 # commands:
568 # - router static
569 # - vrf DEV_SITE
570 # - address-family ipv4 unicast
571 # - no 192.0.2.48/28 vrf test_1 192.0.2.12
572 # - no 192.0.2.48/28 192.0.3.24 GigabitEthernet0/0/0/1
573 # - 192.0.2.48/28 vrf dev_test_2 192.0.2.15 FastEthernet0/0/0/3 description DEV_NEW
574 # after:
575 # - address_families:
576 # - afi: ipv4
577 # routes:
578 # - dest: 192.0.2.16/28
579 # next_hops:
580 # - description: LAB
581 # forward_router_address: 192.0.2.10
582 # interface: FastEthernet0/0/0/1
583 # metric: 120
584 # tag: 10
585 # - interface: FastEthernet0/0/0/5
586 # track: ip_sla_1
587 # - dest: 192.0.2.32/28
588 # next_hops:
589 # - admin_distance: 100
590 # forward_router_address: 192.0.2.11
591 # safi: unicast
592 # - afi: ipv6
593 # routes:
594 # - dest: 2001:db8:1000::/36
595 # next_hops:
596 # - description: DC
597 # interface: FastEthernet0/0/0/7
598 # - forward_router_address: 2001:db8:2000:2::1
599 # interface: FastEthernet0/0/0/8
600 # safi: unicast
601 # - address_families:
602 # - afi: ipv4
603 # routes:
604 # - dest: 192.0.2.48/28
605 # next_hops:
606 # - description: DEV_NEW
607 # dest_vrf: dev_test_2
608 # forward_router_address: 192.0.2.15
609 # interface: FastEthernet0/0/0/3
610 # - dest: 192.0.2.80/28
611 # next_hops:
612 # - dest_vrf: test_1
613 # forward_router_address: 192.0.2.14
614 # interface: FastEthernet0/0/0/2
615 # track: ip_sla_2
616 # vrflabel: 124
617 # safi: unicast
618 # vrf: DEV_SITE
619
620 # After state
621 # ------------
622 # RP/0/RP0/CPU0:ios#sh running-config router static
623 # Sat Feb 22 08:04:07.085 UTC
624 # router static
625 # address-family ipv4 unicast
626 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
627 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
628 # 192.0.2.32/28 192.0.2.11 100
629 # !
630 # address-family ipv6 unicast
631 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
632 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
633 # !
634 # vrf DEV_SITE
635 # address-family ipv4 unicast
636 # 192.0.2.48/28 vrf dev_test_2 FastEthernet0/0/0/3 192.0.2.15 description DEV_NEW
637 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
638 # !
639 # !
640 # !
641
642 # Using overridden to override all static route entries on the device
643
644 # Before state
645 # -------------
646 # RP/0/RP0/CPU0:ios#sh running-config router static
647 # Sat Feb 22 07:59:08.669 UTC
648 # router static
649 # address-family ipv4 unicast
650 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
651 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
652 # 192.0.2.32/28 192.0.2.11 100
653 # !
654 # address-family ipv6 unicast
655 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
656 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
657 # !
658 # vrf DEV_SITE
659 # address-family ipv4 unicast
660 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
661 # 192.0.2.48/28 GigabitEthernet0/0/0/1 192.0.3.24 vrflabel 2302
662 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
663 # !
664 # !
665 # !
666
667 - name: Overridde all static routes configuration with provided configuration
668 cisco.iosxr.iosxr_static_routes:
669 config:
670 - vrf: DEV_NEW
671 address_families:
672 - afi: ipv4
673 safi: unicast
674 routes:
675 - dest: 192.0.2.48/28
676 next_hops:
677 - forward_router_address: 192.0.2.15
678 interface: FastEthernet0/0/0/3
679 description: DEV1
680 - afi: ipv6
681 safi: unicast
682 routes:
683 - dest: '2001:db8:3000::/36'
684 next_hops:
685 - interface: FastEthernet0/0/0/4
686 forward_router_address: '2001:db8:2000:2::2'
687 description: PROD1
688 track: ip_sla_1
689 state: overridden
690
691 # Task Output
692 # -----------
693 # before:
694 # - address_families:
695 # - afi: ipv4
696 # routes:
697 # - dest: 192.0.2.16/28
698 # next_hops:
699 # - description: LAB
700 # forward_router_address: 192.0.2.10
701 # interface: FastEthernet0/0/0/1
702 # metric: 120
703 # tag: 10
704 # - interface: FastEthernet0/0/0/5
705 # track: ip_sla_1
706 # - dest: 192.0.2.32/28
707 # next_hops:
708 # - admin_distance: 100
709 # forward_router_address: 192.0.2.11
710 # safi: unicast
711 # - afi: ipv6
712 # routes:
713 # - dest: 2001:db8:1000::/36
714 # next_hops:
715 # - description: DC
716 # interface: FastEthernet0/0/0/7
717 # - forward_router_address: 2001:db8:2000:2::1
718 # interface: FastEthernet0/0/0/8
719 # safi: unicast
720 # - address_families:
721 # - afi: ipv4
722 # routes:
723 # - dest: 192.0.2.48/28
724 # next_hops:
725 # - description: DEV
726 # dest_vrf: test_1
727 # forward_router_address: 192.0.2.12
728 # - forward_router_address: 192.0.3.24
729 # interface: GigabitEthernet0/0/0/1
730 # vrflabel: 2302
731 # - dest: 192.0.2.80/28
732 # next_hops:
733 # - dest_vrf: test_1
734 # forward_router_address: 192.0.2.14
735 # interface: FastEthernet0/0/0/2
736 # track: ip_sla_2
737 # vrflabel: 124
738 # safi: unicast
739 # vrf: DEV_SITE
740 # commands:
741 # - router static
742 # - no vrf DEV_SITE
743 # - no address-family ipv4 unicast
744 # - no address-family ipv6 unicast
745 # - vrf DEV_NEW
746 # - address-family ipv4 unicast
747 # - 192.0.2.48/28 192.0.2.15 FastEthernet0/0/0/3 description DEV1
748 # - address-family ipv6 unicast
749 # - 2001:db8:3000::/36 2001:db8:2000:2::2 FastEthernet0/0/0/4 description PROD1
750 # track ip_sla_1
751 # after:
752 # - vrf: DEV_NEW
753 # address_families:
754 # - afi: ipv4
755 # safi: unicast
756 # routes:
757 # - dest: 192.0.2.48/28
758 # next_hops:
759 # - forward_router_address: 192.0.2.15
760 # interface: FastEthernet0/0/0/3
761 # description: DEV1
762 # - afi: ipv6
763 # safi: unicast
764 # routes:
765 # - dest: 2001:db8:3000::/36
766 # next_hops:
767 # - interface: FastEthernet0/0/0/4
768 # forward_router_address: 2001:db8:2000:2::2
769 # description: PROD1
770 # track: ip_sla_1
771
772 # After state
773 # -------------
774 # RP/0/RP0/CPU0:ios#sh running-config router static
775 # Sat Feb 22 08:07:41.516 UTC
776 # router static
777 # vrf DEV_NEW
778 # address-family ipv4 unicast
779 # 192.0.2.48/28 FastEthernet0/0/0/3 192.0.2.15 description DEV1
780 # !
781 # address-family ipv6 unicast
782 # 2001:db8:3000::/36 FastEthernet0/0/0/4 2001:db8:2000:2::2 description PROD1 track ip_sla_1
783 # !
784 # !
785 # !
786
787 # Using deleted to delete all destination network entries under a single AFI
788
789 # Before state
790 # -------------
791 # RP/0/RP0/CPU0:ios#sh running-config router static
792 # Sat Feb 22 07:59:08.669 UTC
793 # router static
794 # address-family ipv4 unicast
795 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
796 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
797 # 192.0.2.32/28 192.0.2.11 100
798 # !
799 # address-family ipv6 unicast
800 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
801 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
802 # !
803 # vrf DEV_SITE
804 # address-family ipv4 unicast
805 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
806 # 192.0.2.48/28 GigabitEthernet0/0/0/1 192.0.3.24 vrflabel 2302
807 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
808 # !
809 # !
810 # !
811
812 - name: Delete all destination network entries under a single AFI
813 cisco.iosxr.iosxr_static_routes:
814 config:
815 - vrf: DEV_SITE
816 address_families:
817 - afi: ipv4
818 safi: unicast
819 state: deleted
820
821 # Task output
822 # -----------------------
823 # before:
824 # - address_families:
825 # - afi: ipv4
826 # routes:
827 # - dest: 192.0.2.16/28
828 # next_hops:
829 # - description: LAB
830 # forward_router_address: 192.0.2.10
831 # interface: FastEthernet0/0/0/1
832 # metric: 120
833 # tag: 10
834 # - interface: FastEthernet0/0/0/5
835 # track: ip_sla_1
836 # - dest: 192.0.2.32/28
837 # next_hops:
838 # - admin_distance: 100
839 # forward_router_address: 192.0.2.11
840 # safi: unicast
841 # - afi: ipv6
842 # routes:
843 # - dest: 2001:db8:1000::/36
844 # next_hops:
845 # - description: DC
846 # interface: FastEthernet0/0/0/7
847 # - forward_router_address: 2001:db8:2000:2::1
848 # interface: FastEthernet0/0/0/8
849 # safi: unicast
850 # - address_families:
851 # - afi: ipv4
852 # routes:
853 # - dest: 192.0.2.48/28
854 # next_hops:
855 # - description: DEV
856 # dest_vrf: test_1
857 # forward_router_address: 192.0.2.12
858 # - forward_router_address: 192.0.3.24
859 # interface: GigabitEthernet0/0/0/1
860 # vrflabel: 2302
861 # - dest: 192.0.2.80/28
862 # next_hops:
863 # - dest_vrf: test_1
864 # forward_router_address: 192.0.2.14
865 # interface: FastEthernet0/0/0/2
866 # track: ip_sla_2
867 # vrflabel: 124
868 # safi: unicast
869 # vrf: DEV_SITE
870 # commands:
871 # - router static
872 # - vrf DEV_SITE
873 # - no address-family ipv4 unicast
874 # after:
875 # - address_families:
876 # - afi: ipv4
877 # routes:
878 # - dest: 192.0.2.16/28
879 # next_hops:
880 # - description: LAB
881 # forward_router_address: 192.0.2.10
882 # interface: FastEthernet0/0/0/1
883 # metric: 120
884 # tag: 10
885 # - interface: FastEthernet0/0/0/5
886 # track: ip_sla_1
887 # - dest: 192.0.2.32/28
888 # next_hops:
889 # - admin_distance: 100
890 # forward_router_address: 192.0.2.11
891 # safi: unicast
892 # - afi: ipv6
893 # routes:
894 # - dest: 2001:db8:1000::/36
895 # next_hops:
896 # - description: DC
897 # interface: FastEthernet0/0/0/7
898 # - forward_router_address: 2001:db8:2000:2::1
899 # interface: FastEthernet0/0/0/8
900 # safi: unicast
901 # - address_families:
902 # - afi: ipv4
903 # routes:
904 # - dest: 192.0.2.48/28
905 # next_hops:
906 # - description: DEV
907 # dest_vrf: test_1
908 # forward_router_address: 192.0.2.12
909 # - forward_router_address: 192.0.3.24
910 # interface: GigabitEthernet0/0/0/1
911 # vrflabel: 2302
912 # - dest: 192.0.2.80/28
913 # next_hops:
914 # - dest_vrf: test_1
915 # forward_router_address: 192.0.2.14
916 # interface: FastEthernet0/0/0/2
917 # track: ip_sla_2
918 # vrflabel: 124
919 # safi: unicast
920 # - vrf: DEV_SITE
921
922 # After state
923 # ------------
924
925 # RP/0/RP0/CPU0:ios#sh running-config router static
926 # Sat Feb 22 08:16:41.464 UTC
927 # router static
928 # address-family ipv4 unicast
929 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
930 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
931 # 192.0.2.32/28 192.0.2.11 100
932 # !
933 # address-family ipv6 unicast
934 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
935 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
936 # !
937 # vrf DEV_SITE
938 # !
939 # !
940
941 # Using deleted to remove all static route entries from the device
942
943 # Before state
944 # -------------
945 # RP/0/RP0/CPU0:ios#sh running-config router static
946 # Sat Feb 22 07:59:08.669 UTC
947 # router static
948 # address-family ipv4 unicast
949 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
950 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
951 # 192.0.2.32/28 192.0.2.11 100
952 # !
953 # address-family ipv6 unicast
954 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
955 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
956 # !
957 # vrf DEV_SITE
958 # address-family ipv4 unicast
959 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
960 # 192.0.2.48/28 GigabitEthernet0/0/0/1 192.0.3.24 vrflabel 2302
961 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
962 # !
963 # !
964 # !
965
966 - name: Delete static routes configuration
967 cisco.iosxr.iosxr_static_routes:
968 state: deleted
969
970 # Task output
971 # -----------------------
972 # before:
973 # - address_families:
974 # - afi: ipv4
975 # routes:
976 # - dest: 192.0.2.16/28
977 # next_hops:
978 # - description: LAB
979 # forward_router_address: 192.0.2.10
980 # interface: FastEthernet0/0/0/1
981 # metric: 120
982 # tag: 10
983 # - interface: FastEthernet0/0/0/5
984 # track: ip_sla_1
985 # - dest: 192.0.2.32/28
986 # next_hops:
987 # - admin_distance: 100
988 # forward_router_address: 192.0.2.11
989 # safi: unicast
990 # - afi: ipv6
991 # routes:
992 # - dest: 2001:db8:1000::/36
993 # next_hops:
994 # - description: DC
995 # interface: FastEthernet0/0/0/7
996 # - forward_router_address: 2001:db8:2000:2::1
997 # interface: FastEthernet0/0/0/8
998 # safi: unicast
999 # - address_families:
1000 # - afi: ipv4
1001 # routes:
1002 # - dest: 192.0.2.48/28
1003 # next_hops:
1004 # - description: DEV
1005 # dest_vrf: test_1
1006 # forward_router_address: 192.0.2.12
1007 # - forward_router_address: 192.0.3.24
1008 # interface: GigabitEthernet0/0/0/1
1009 # vrflabel: 2302
1010 # - dest: 192.0.2.80/28
1011 # next_hops:
1012 # - dest_vrf: test_1
1013 # forward_router_address: 192.0.2.14
1014 # interface: FastEthernet0/0/0/2
1015 # track: ip_sla_2
1016 # vrflabel: 124
1017 # safi: unicast
1018 # vrf: DEV_SITE
1019 # commands:
1020 # - no router static
1021 # after: []
1022 # After state
1023 # ------------
1024 # RP/0/RP0/CPU0:ios#sh running-config router static
1025 # Sat Feb 22 08:50:43.038 UTC
1026 # % No such configuration item(s)
1027
1028 # Using gathered to gather static route facts from the device
1029
1030 - name: Gather static routes facts from the device using iosxr_static_routes module
1031 cisco.iosxr.iosxr_static_routes:
1032 state: gathered
1033
1034 # Task output (redacted)
1035 # -----------------------
1036 # "gathered": [
1037 # {
1038 # "address_families": [
1039 # {
1040 # "afi": "ipv4",
1041 # "routes": [
1042 # {
1043 # "dest": "192.0.2.16/28",
1044 # "next_hops": [
1045 # {
1046 # "description": "LAB",
1047 # "forward_router_address": "192.0.2.10",
1048 # "interface": "FastEthernet0/0/0/1",
1049 # "metric": 120,
1050 # "tag": 10
1051 # },
1052 # {
1053 # "interface": "FastEthernet0/0/0/5",
1054 # "track": "ip_sla_1"
1055 # }
1056 # ]
1057 # },
1058 # {
1059 # "dest": "192.0.2.32/28",
1060 # "next_hops": [
1061 # {
1062 # "admin_distance": 100,
1063 # "forward_router_address": "192.0.2.11"
1064 # }
1065 # ]
1066 # }
1067 # ],
1068 # "safi": "unicast"
1069 # },
1070 # {
1071 # "afi": "ipv6",
1072 # "routes": [
1073 # {
1074 # "dest": "2001:db8:1000::/36",
1075 # "next_hops": [
1076 # {
1077 # "description": "DC",
1078 # "interface": "FastEthernet0/0/0/7"
1079 # },
1080 # {
1081 # "forward_router_address": "2001:db8:2000:2::1",
1082 # "interface": "FastEthernet0/0/0/8"
1083 # }
1084 # ]
1085 # }
1086 # ],
1087 # "safi": "unicast"
1088 # }
1089 # ]
1090 # },
1091 # {
1092 # "address_families": [
1093 # {
1094 # "afi": "ipv4",
1095 # "routes": [
1096 # {
1097 # "dest": "192.0.2.48/28",
1098 # "next_hops": [
1099 # {
1100 # "description": "DEV",
1101 # "dest_vrf": "test_1",
1102 # "forward_router_address": "192.0.2.12"
1103 # },
1104 # {
1105 # "forward_router_address": "192.0.3.24",
1106 # "interface": "GigabitEthernet0/0/0/1",
1107 # "vrflabel": 2302
1108 # }
1109 # ]
1110 # },
1111 # {
1112 # "dest": "192.0.2.80/28",
1113 # "next_hops": [
1114 # {
1115 # "dest_vrf": "test_1",
1116 # "forward_router_address": "192.0.2.14",
1117 # "interface": "FastEthernet0/0/0/2",
1118 # "track": "ip_sla_2",
1119 # "vrflabel": 124
1120 # }
1121 # ]
1122 # }
1123 # ],
1124 # "safi": "unicast"
1125 # }
1126 # ],
1127 # "vrf": "DEV_SITE"
1128 # }
1129 # ]
1130
1131 # Using rendered
1132
1133 - name: Render platform specific commands (without connecting to the device)
1134 cisco.iosxr.iosxr_static_routes: null
1135 config:
1136 - vrf: DEV_SITE
1137 address_families:
1138 - afi: ipv4
1139 safi: unicast
1140 routes:
1141 - dest: 192.0.2.48/28
1142 next_hops:
1143 - forward_router_address: 192.0.2.12
1144 description: DEV
1145 dest_vrf: test_1
1146 - dest: 192.0.2.80/28
1147 next_hops:
1148 - interface: FastEthernet0/0/0/2
1149 forward_router_address: 192.0.2.14
1150 dest_vrf: test_1
1151 track: ip_sla_2
1152 vrflabel: 124
1153
1154 # Task Output (redacted)
1155 # -----------------------
1156 # "rendered": [
1157 # "router static"s,
1158 # "vrf DEV_SITE",
1159 # "address-family ipv4 unicast",
1160 # "192.0.2.48/28 vrf test_1 192.0.2.12 description DEV",
1161 # "192.0.2.80/28 vrf test_1 192.0.2.14 FastEthernet0/0/0/2 track ip_sla_2 vrflabel 124"
1162
1163 # Using parsed
1164
1165 # parsed.cfg
1166 # ------------
1167 # Fri Nov 29 21:10:41.896 UTC
1168 # router static
1169 # address-family ipv4 unicast
1170 # 192.0.2.16/28 FastEthernet0/0/0/1 192.0.2.10 tag 10 description LAB metric 120
1171 # 192.0.2.16/28 FastEthernet0/0/0/5 track ip_sla_1
1172 # 192.0.2.32/28 192.0.2.11 100
1173 # !
1174 # address-family ipv6 unicast
1175 # 2001:db8:1000::/36 FastEthernet0/0/0/7 description DC
1176 # 2001:db8:1000::/36 FastEthernet0/0/0/8 2001:db8:2000:2::1
1177 # !
1178 # vrf DEV_SITE
1179 # address-family ipv4 unicast
1180 # 192.0.2.48/28 vrf test_1 192.0.2.12 description DEV
1181 # 192.0.2.80/28 vrf test_1 FastEthernet0/0/0/2 192.0.2.14 vrflabel 124 track ip_sla_2
1182 # !
1183 # !
1184 # !
1185
1186 - name: Use parsed state to convert externally supplied device specific static routes
1187 commands to structured format
1188 cisco.iosxr.iosxr_static_routes:
1189 running_config: "{{ lookup('file', '../../fixtures/parsed.cfg') }}"
1190 state: parsed
1191
1192 # Task output (redacted)
1193 # -----------------------
1194 # "parsed": [
1195 # {
1196 # "address_families": [
1197 # {
1198 # "afi": "ipv4",
1199 # "routes": [
1200 # {
1201 # "dest": "192.0.2.16/28",
1202 # "next_hops": [
1203 # {
1204 # "description": "LAB",
1205 # "forward_router_address": "192.0.2.10",
1206 # "interface": "FastEthernet0/0/0/1",
1207 # "metric": 120,
1208 # "tag": 10
1209 # },
1210 # {
1211 # "interface": "FastEthernet0/0/0/5",
1212 # "track": "ip_sla_1"
1213 # }
1214 # ]
1215 # },
1216 # {
1217 # "dest": "192.0.2.32/28",
1218 # "next_hops": [
1219 # {
1220 # "admin_distance": 100,
1221 # "forward_router_address": "192.0.2.11"
1222 # }
1223 # ]
1224 # }
1225 # ],
1226 # "safi": "unicast"
1227 # },
1228 # {
1229 # "afi": "ipv6",
1230 # "routes": [
1231 # {
1232 # "dest": "2001:db8:1000::/36",
1233 # "next_hops": [
1234 # {
1235 # "description": "DC",
1236 # "interface": "FastEthernet0/0/0/7"
1237 # },
1238 # {
1239 # "forward_router_address": "2001:db8:2000:2::1",
1240 # "interface": "FastEthernet0/0/0/8"
1241 # }
1242 # ]
1243 # }
1244 # ],
1245 # "safi": "unicast"
1246 # }
1247 # ]
1248 # },
1249 # {
1250 # "address_families": [
1251 # {
1252 # "afi": "ipv4",
1253 # "routes": [
1254 # {
1255 # "dest": "192.0.2.48/28",
1256 # "next_hops": [
1257 # {
1258 # "description": "DEV",
1259 # "dest_vrf": "test_1",
1260 # "forward_router_address": "192.0.2.12"
1261 # }
1262 # ]
1263 # },
1264 # {
1265 # "dest": "192.0.2.80/28",
1266 # "next_hops": [
1267 # {
1268 # "dest_vrf": "test_1",
1269 # "forward_router_address": "192.0.2.14",
1270 # "interface": "FastEthernet0/0/0/2",
1271 # "track": "ip_sla_2",
1272 # "vrflabel": 124
1273 # }
1274 # ]
1275 # }
1276 # ],
1277 # "safi": "unicast"
1278 # }
1279 # ],
1280 # "vrf": "DEV_SITE"
1281 # }
1282 # ]
1283 # }
1284 """
1285 RETURN = """
1286 before:
1287 description: The configuration prior to the model invocation.
1288 returned: always
1289 type: list
1290 sample: >
1291 The configuration returned will always be in the same format
1292 of the parameters above.
1293 after:
1294 description: The resulting configuration model invocation.
1295 returned: when changed
1296 type: list
1297 sample: >
1298 The configuration returned will always be in the same format
1299 of the parameters above.
1300 commands:
1301 description: The set of commands pushed to the remote device.
1302 returned: always
1303 type: list
1304 sample:
1305 - router static
1306 - vrf dev_site
1307 - address-family ipv4 unicast
1308 - 192.0.2.48/28 192.0.2.12 FastEthernet0/0/0/1 track ip_sla_10 description dev1
1309 - address-family ipv6 unicast
1310 - no 2001:db8:1000::/36
1311 - 2001:db8:3000::/36 2001:db8:2000:2::2 FastEthernet0/0/0/4 track ip_sla_11 description prod1
1312 """
1313
1314
1315 from ansible.module_utils.basic import AnsibleModule
1316
1317 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.static_routes.static_routes import (
1318 Static_routesArgs,
1319 )
1320 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.static_routes.static_routes import (
1321 Static_routes,
1322 )
1323
1324
1325 def main():
1326 """
1327 Main entry point for module execution
1328
1329 :returns: the result form module invocation
1330 """
1331 required_if = [
1332 ("state", "merged", ("config",)),
1333 ("state", "replaced", ("config",)),
1334 ("state", "overridden", ("config",)),
1335 ("state", "parsed", ("running_config",)),
1336 ]
1337 mutually_exclusive = [("config", "running_config")]
1338
1339 module = AnsibleModule(
1340 argument_spec=Static_routesArgs.argument_spec,
1341 required_if=required_if,
1342 mutually_exclusive=mutually_exclusive,
1343 supports_check_mode=True,
1344 )
1345
1346 result = Static_routes(module).execute_module()
1347 module.exit_json(**result)
1348
1349
1350 if __name__ == "__main__":
1351 main()