Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_vrf_address_family.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2024 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 nxos_vrf_address_family
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: nxos_vrf_address_family
18 short_description: Resource module to configure VRF address family definitions.
19 description: This module provides declarative management of VRF definitions on Cisco NXOS.
20 version_added: 9.3.0
21 author: Vinay Mulugund (@roverflow)
22 notes:
23 - Tested against NX-OS 9.3.6.
24 - This module works with connection C(network_cli) and C(httpapi).
25 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_nxos.html)
26 options:
27 config:
28 description: A list of device configurations for VRF address family.
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description: Name of the VRF.
34 type: str
35 required: true
36 address_families:
37 description: Enable address family and enter its config mode - AFI/SAFI configuration
38 type: list
39 elements: dict
40 suboptions:
41 afi:
42 description: Address Family Identifier (AFI)
43 type: str
44 choices: ["ipv4", "ipv6"]
45 safi:
46 description: Address Family modifier
47 type: str
48 choices: ["multicast", "unicast"]
49 maximum:
50 description: Set a limit of routes
51 type: dict
52 suboptions:
53 max_routes:
54 description: Maximum number of routes allowed
55 type: int
56 max_route_options:
57 description: Configure the options for maximum routes
58 type: dict
59 suboptions:
60 warning_only:
61 description: Configure only give a warning message if limit is exceeded
62 type: bool
63 threshold:
64 description: Configure threshold & its options
65 type: dict
66 suboptions:
67 threshold_value:
68 description: Threshold value (%) at which to generate a warning msg
69 type: int
70 reinstall_threshold:
71 description: Threshold value (%) at which to reinstall routes back to VRF
72 type: int
73 route_target:
74 description: Specify Target VPN Extended Communities
75 type: list
76 elements: dict
77 suboptions:
78 import:
79 description: Import Target-VPN community
80 type: str
81 export:
82 description: Export Target-VPN community
83 type: str
84 export:
85 description: VRF export
86 type: list
87 elements: dict
88 suboptions:
89 map:
90 description: Route-map based VRF export
91 type: str
92 vrf:
93 description: Virtual Router Context
94 type: dict
95 suboptions:
96 max_prefix:
97 description: Maximum prefix limit
98 type: int
99 map_import:
100 description: Route-map based VRF import
101 type: str
102 allow_vpn:
103 description: Allow re-importation of VPN imported routes
104 type: bool
105 import:
106 description: VRF import
107 type: list
108 elements: dict
109 suboptions:
110 map:
111 description: Route-map based VRF export
112 type: str
113 vrf:
114 description: Virtual Router Context
115 type: dict
116 suboptions:
117 max_prefix:
118 description: Maximum prefix limit
119 type: int
120 map_import:
121 description: Route-map based VRF import
122 type: str
123 advertise_vpn:
124 description: Allow leaked routes to be advertised to VPN
125 type: bool
126 running_config:
127 description:
128 - This option is used only with state I(parsed).
129 - The value of this option should be the output received from the NX-OS device by
130 executing the command B(show running-config | section ^vrf).
131 - The state I(parsed) reads the configuration from C(running_config) option and
132 transforms it into Ansible structured data as per the resource module's argspec
133 and the value is then returned in the I(parsed) key within the result.
134 type: str
135 state:
136 choices: [parsed, gathered, deleted, purged, merged, replaced, rendered, overridden]
137 default: merged
138 description:
139 - The state the configuration should be left in
140 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
141 on the device.
142 - The state I(rendered) will transform the configuration in C(config) option to
143 platform specific CLI commands which will be returned in the I(rendered) key
144 within the result. For state I(rendered) active connection to remote host is
145 not required.
146 - The state I(gathered) will fetch the running configuration from device and transform
147 it into structured data in the format as per the resource module argspec and
148 the value is returned in the I(gathered) key within the result.
149 - The state I(parsed) reads the configuration from C(running_config) option and
150 transforms it into JSON format as per the resource module parameters and the
151 value is returned in the I(parsed) key within the result. The value of C(running_config)
152 option should be the same format as the output of command I(show running-config | section ^vrf).
153 connection to remote host is not required.
154 type: str
155 """
156
157 EXAMPLES = """
158 # Using merged
159
160 # Before state:
161 # -------------
162 #
163 # nxos#show running-config | section ^vrf
164
165 - name: Merge provided configuration with device configuration
166 register: result
167 cisco.nxos.nxos_vrf_address_family:
168 config:
169 - name: VRF1
170 address_families:
171 - afi: ipv4
172 safi: unicast
173 route_target:
174 - export: "65512:200"
175 maximum:
176 max_routes: 500
177 max_route_options:
178 threshold:
179 threshold_value: 60
180 reinstall_threshold: 80
181 export:
182 - map: "22"
183 - vrf:
184 allow_vpn: true
185 map_import: "44"
186 - vrf:
187 allow_vpn: true
188 - afi: ipv6
189 safi: unicast
190 maximum:
191 max_routes: 1000
192 route_target:
193 - import: "65512:200"
194 import:
195 - map: "22"
196 - vrf:
197 advertise_vpn: true
198 map_import: "44"
199 - vrf:
200 advertise_vpn: true
201 state: merged
202
203 # Task Output:
204 # ------------
205
206 # before: {}
207 # commands:
208 # - vrf context VRF1
209 # - address-family ipv4 unicast
210 # - maximum routes 500 60 reinstall 80
211 # - route-target export 65512:200
212 # - export map 22
213 # - export vrf default map 44 allow-vpn
214 # - export vrf allow-vpn
215 # - address-family ipv6 unicast
216 # - maximum routes 1000
217 # - route-target import 65512:200
218 # - import map 22
219 # - import vrf default map 44 advertise-vpn
220 # - import vrf advertise-vpn
221 # after:
222 # - address_families:
223 # - afi: ipv4
224 # export:
225 # - map: "22"
226 # - vrf:
227 # allow_vpn: true
228 # map_import: "44"
229 # - vrf:
230 # allow_vpn: true
231 # maximum:
232 # max_route_options:
233 # threshold:
234 # reinstall_threshold: 80
235 # threshold_value: 60
236 # max_routes: 500
237 # route_target:
238 # - export: 65512:200
239 # safi: unicast
240 # - afi: ipv6
241 # import:
242 # - map: "22"
243 # - vrf:
244 # advertise_vpn: true
245 # map_import: "44"
246 # - vrf:
247 # advertise_vpn: true
248 # maximum:
249 # max_routes: 1000
250 # route_target:
251 # - import: 65512:200
252 # safi: unicast
253 # name: VRF1
254
255 # After state:
256 # ------------
257 #
258 # nxos#show running-config | section ^vrf
259 # vrf context VRF1
260 # address-family ipv4 unicast
261 # route-target export 65512:200
262 # export map 22
263 # export vrf default map 44 allow-vpn
264 # export vrf allow-vpn
265 # maximum routes 500 60 reinstall 80
266 # address-family ipv6 unicast
267 # route-target import 65512:200
268 # import map 22
269 # import vrf default map 44 advertise-vpn
270 # import vrf advertise-vpn
271 # maximum routes 1000
272
273 # Using deleted
274
275 # Before state:
276 # -------------
277 #
278 # nxos#show running-config | section ^vrf
279 # vrf context VRF1
280 # address-family ipv4 unicast
281 # route-target import 64512:200
282 # route-target export 64512:200
283 # export map 22
284 # export vrf default map 44 allow-vpn
285 # export vrf allow-vpn
286 # maximum routes 900 22 reinstall 44
287
288 - name: Delete given vrf address family configuration
289 register: result
290 cisco.nxos.nxos_vrf_address_family:
291 config:
292 - name: VRF1
293 address_families:
294 - afi: ipv4
295 safi: unicast
296 route_target:
297 - import: 64512:200
298 export:
299 - map: "22"
300 maximum:
301 max_routes: 900
302 max_route_options:
303 threshold:
304 threshold_value: 22
305 reinstall_threshold: 44
306 state: deleted
307
308 # Task Output:
309 # ------------
310 #
311 # before:
312 # - address_families:
313 # - afi: ipv4
314 # export:
315 # - map: "22"
316 # - vrf:
317 # allow_vpn: true
318 # map_import: "44"
319 # - vrf:
320 # allow_vpn: true
321 # maximum:
322 # max_route_options:
323 # threshold:
324 # reinstall_threshold: 44
325 # threshold_value: 22
326 # max_routes: 900
327 # route_target:
328 # - import: "64512:200"
329 # - export: "64512:200"
330 # safi: unicast
331 # name: VRF1
332
333 # commands:
334 # - vrf context VRF1
335 # - address-family ipv4 unicast
336 # - no maximum routes 900 22 reinstall 44
337 # - no route-target import 64512:200
338 # - no export map 22
339 # after:
340 # - address_families:
341 # - afi: ipv4
342 # export:
343 # - vrf:
344 # allow_vpn: true
345 # map_import: "44"
346 # - vrf:
347 # allow_vpn: true
348 # route_target:
349 # - export: "64512:200"
350 # safi: unicast
351 # name: VRF1
352
353 # Using purged
354
355 # Before state:
356 # -------------
357 #
358 # nxos#show running-config | section ^vrf
359 # vrf context VRF1
360 # address-family ipv4 unicast
361 # route-target export 65512:200
362 # export map 22
363 # export vrf default map 44 allow-vpn
364 # export vrf allow-vpn
365 # maximum routes 500 60 reinstall 80
366 # address-family ipv6 unicast
367 # route-target import 65512:200
368 # import map 22
369 # import vrf default map 44 advertise-vpn
370 # import vrf advertise-vpn
371 # maximum routes 1000
372
373 - name: Purge the configuration of VRF address family
374 register: result
375 cisco.nxos.nxos_vrf_address_family:
376 config:
377 - name: VRF1
378 address_families:
379 - afi: ipv4
380 safi: unicast
381 - afi: ipv6
382 safi: unicast
383 state: purged
384
385 # Task Output:
386 # ------------
387 #
388 # before:
389 # - address_families:
390 # - afi: ipv4
391 # export:
392 # - map: "22"
393 # - vrf:
394 # allow_vpn: true
395 # map_import: "44"
396 # - vrf:
397 # allow_vpn: true
398 # maximum:
399 # max_route_options:
400 # threshold:
401 # reinstall_threshold: 80
402 # threshold_value: 60
403 # max_routes: 500
404 # route_target:
405 # - export: 65512:200
406 # safi: unicast
407 # - afi: ipv6
408 # import:
409 # - map: "22"
410 # - vrf:
411 # advertise_vpn: true
412 # map_import: "44"
413 # - vrf:
414 # advertise_vpn: true
415 # maximum:
416 # max_routes: 1000
417 # route_target:
418 # - import: 65512:200
419 # safi: unicast
420 # name: VRF1
421 # commands:
422 # - vrf context VRF1
423 # - no address-family ipv4 unicast
424 # - no address-family ipv6 unicast
425 # after: {}
426
427
428 # Using overridden
429
430 # Before state:
431 # -------------
432 #
433 # nxos#show running-config | section ^vrf
434 # vrf context VRF1
435 # address-family ipv4 unicast
436 # route-target import 64512:200
437 # address-family ipv6 unicast
438 # route-target import 554832:500
439
440 - name: Override the provided configuration with the existing running configuration
441 cisco.nxos.nxos_vrf_address_family:
442 config:
443 - name: VRF1
444 address_families:
445 - afi: ipv6
446 safi: unicast
447 route_target:
448 - export: 65512:200
449 maximum:
450 max_routes: 500
451 max_route_options:
452 threshold:
453 threshold_value: 60
454 reinstall_threshold: 80
455 export:
456 - map: "22"
457 - vrf:
458 allow_vpn: true
459 map_import: "44"
460 - vrf:
461 allow_vpn: true
462 - name: temp
463 address_families:
464 - afi: ipv4
465 safi: unicast
466 route_target:
467 - import: 65512:200
468 maximum:
469 max_routes: 1000
470 export:
471 - map: "26"
472 - vrf:
473 allow_vpn: true
474 map_import: "46"
475 state: overridden
476
477 # Task Output:
478 # ------------
479 #
480 # before:
481 # - address_families:
482 # - afi: ipv4
483 # route_target:
484 # - import: 64512:200
485 # safi: unicast
486 # - afi: ipv6
487 # route_target:
488 # - import: 554832:500
489 # safi: unicast
490 # name: VRF1
491 #
492 # commands:
493 # - vrf context VRF1
494 # - address-family ipv4 unicast
495 # - no route-target import 64512:200
496 # - address-family ipv6 unicast
497 # - maximum routes 500 60 reinstall 80
498 # - no route-target import 554832:500
499 # - route-target export 65512:200
500 # - export map 22
501 # - export vrf default map 44 allow-vpn
502 # - export vrf allow-vpn
503 # - vrf context temp
504 # - address-family ipv4 unicast
505 # - maximum routes 1000
506 # - route-target import 65512:200
507 # - export map 26
508 # - export vrf default map 46 allow-vpn
509 # after:
510 # - address_families:
511 # - afi: ipv4
512 # safi: unicast
513 # - afi: ipv6
514 # export:
515 # - map: "22"
516 # - vrf:
517 # allow_vpn: true
518 # map_import: "44"
519 # - vrf:
520 # allow_vpn: true
521 # maximum:
522 # max_route_options:
523 # threshold:
524 # reinstall_threshold: 80
525 # threshold_value: 60
526 # max_routes: 500
527 # route_target:
528 # - export: 65512:200
529 # safi: unicast
530 # name: VRF1
531 # - address_families:
532 # - afi: ipv4
533 # export:
534 # - map: "26"
535 # - vrf:
536 # allow_vpn: true
537 # map_import: "46"
538 # maximum:
539 # max_routes: 1000
540 # route_target:
541 # - import: 65512:200
542 # safi: unicast
543 # name: temp
544
545 # Using replaced
546
547 # Before state:
548 # -------------
549 #
550 # nxos# show running-config | section ^vrf
551 # vrf context VRF1
552 # address-family ipv4 unicast
553 # route-target import 64512:200
554 # address-family ipv6 unicast
555 # route-target import 554832:500
556
557 - name: Replaced state for VRF configuration
558 cisco.nxos.nxos_vrf_global:
559 config:
560 vrfs:
561 - ip:
562 name_server:
563 address_list:
564 - 192.168.255.1
565 route:
566 - destination: 192.168.255.1
567 source: 0.0.0.0/0
568 name: management
569 - name: temp
570 description: Test
571 ip:
572 auto_discard: true
573 domain_list:
574 - invalid.com
575 - example.com
576 domain_name: test.org
577 state: replaced
578
579 # Task Output:
580 # ------------
581 #
582 # before:
583 # - address_families:
584 # - afi: ipv4
585 # route_target:
586 # - import: 64512:200
587 # safi: unicast
588 # - afi: ipv6
589 # route_target:
590 # - import: 554832:500
591 # safi: unicast
592 # name: VRF1
593 # commands:
594 # - vrf context VRF1
595 # - address-family ipv4 unicast
596 # - no route-target import 64512:200
597 # - address-family ipv6 unicast
598 # - maximum routes 500 60 reinstall 80
599 # - no route-target import 554832:500
600 # - route-target export 65512:200
601 # - export map 22
602 # - export vrf default map 44 allow-vpn
603 # - export vrf allow-vpn
604 # - vrf context temp
605 # - address-family ipv4 unicast
606 # - maximum routes 1000
607 # - route-target import 65512:200
608 # - export map 26
609 # - export vrf default map 46 allow-vpn
610 # after:
611 # - address_families:
612 # - afi: ipv4
613 # safi: unicast
614 # - afi: ipv6
615 # export:
616 # - map: "22"
617 # - vrf:
618 # allow_vpn: true
619 # map_import: "44"
620 # - vrf:
621 # allow_vpn: true
622 # maximum:
623 # max_route_options:
624 # threshold:
625 # reinstall_threshold: 80
626 # threshold_value: 60
627 # max_routes: 500
628 # route_target:
629 # - export: 65512:200
630 # safi: unicast
631 # name: VRF1
632 # - address_families:
633 # - afi: ipv4
634 # export:
635 # - map: "26"
636 # - vrf:
637 # allow_vpn: true
638 # map_import: "46"
639 # maximum:
640 # max_routes: 1000
641 # route_target:
642 # - import: 65512:200
643 # safi: unicast
644 # name: temp
645 #
646 # After state:
647 # ------------
648 # router-ios#show running-config | section ^vrf
649 # vrf context VRF1
650 # address-family ipv6 unicast
651 # route-target export 65512:200
652 # export map 22
653 # export vrf default map 44 allow-vpn
654 # export vrf allow-vpn
655 # vrf context temp
656 # address-family ipv4 unicast
657 # route-target import 65512:200
658 # export map 26
659 # export vrf default map 46 allow-vpn
660 # maximum routes 1000
661
662 # Using gathered
663
664 # Before state:
665 # -------------
666 #
667 # nxos#show running-config | section ^vrf
668 # vrf context VRF1
669 # address-family ipv4 unicast
670 # route-target export 65512:200
671 # export map 22
672 # export vrf default map 44 allow-vpn
673 # export vrf allow-vpn
674 # maximum routes 500 60 reinstall 80
675 # address-family ipv6 unicast
676 # route-target import 65512:200
677 # import map 22
678 # import vrf default map 44 advertise-vpn
679 # import vrf advertise-vpn
680 # maximum routes 1000
681
682 - name: Gathered state for VRF configuration
683 cisco.nxos.nxos_vrf_global:
684 config:
685 state: gathered
686
687 # Task Output:
688 # ------------
689 #
690 # gathered:
691 # - address_families:
692 # - afi: ipv4
693 # export:
694 # - map: "22"
695 # - vrf:
696 # allow_vpn: true
697 # map_import: "44"
698 # - vrf:
699 # allow_vpn: true
700 # maximum:
701 # max_route_options:
702 # threshold:
703 # reinstall_threshold: 80
704 # threshold_value: 60
705 # max_routes: 500
706 # route_target:
707 # - export: 65512:200
708 # safi: unicast
709 # - afi: ipv6
710 # import:
711 # - map: "22"
712 # - vrf:
713 # advertise_vpn: true
714 # map_import: "44"
715 # - vrf:
716 # advertise_vpn: true
717 # maximum:
718 # max_routes: 1000
719 # route_target:
720 # - import: 65512:200
721 # safi: unicast
722 # name: VRF1
723
724 # Using rendered
725
726 - name: Render provided configuration with device configuration
727 register: result
728 cisco.nxos.nxos_vrf_address_family:
729 config:
730 - name: VRF1
731 address_families:
732 - afi: ipv6
733 safi: unicast
734 route_target:
735 - export: 65512:200
736 maximum:
737 max_routes: 500
738 max_route_options:
739 threshold:
740 threshold_value: 60
741 reinstall_threshold: 80
742 export:
743 - map: "22"
744 - vrf:
745 allow_vpn: true
746 map_import: "44"
747 - vrf:
748 allow_vpn: true
749 - name: temp
750 address_families:
751 - afi: ipv4
752 safi: unicast
753 route_target:
754 - import: 65512:200
755 maximum:
756 max_routes: 1000
757 export:
758 - map: "26"
759 - vrf:
760 allow_vpn: true
761 map_import: "46"
762 state: rendered
763
764 # Task Output:
765 # ------------
766 #
767 # commands:
768 # - vrf context VRF1
769 # - address-family ipv6 unicast
770 # - maximum routes 500 60 reinstall 80
771 # - route-target export 65512:200
772 # - export map 22
773 # - export vrf default map 44 allow-vpn
774 # - export vrf allow-vpn
775 # - vrf context temp
776 # - address-family ipv4 unicast
777 # - maximum routes 1000
778 # - route-target import 65512:200
779 # - export map 26
780 # - export vrf default map 46 allow-vpn
781
782 # Using Parsed
783
784 # Parsed Config:
785 # -------------
786 # vrf context VRF1
787 # address-family ipv4 unicast
788 # route-target import 64512:200
789 # route-target export 64512:200
790 # export map 22
791 # export vrf default map 44 allow-vpn
792 # export vrf allow-vpn
793 # maximum routes 900 22 reinstall 44
794 # address-family ipv6 unicast
795 # route-target import 554832:500
796
797 - name: Parse the commands for provided configuration
798 register: result
799 cisco.nxos.nxos_vrf_address_family:
800 running_config: "{{ lookup('file', '_parsed.cfg') }}"
801 state: parsed
802
803 # Task Output:
804 # ------------
805 # parsed:
806 # - name: VRF1
807 # address_families:
808 # - afi: ipv4
809 # safi: unicast
810 # route_target:
811 # - import: 64512:200
812 # - export: 64512:200
813 # export:
814 # - map: "22"
815 # - vrf:
816 # allow_vpn: true
817 # map_import: "44"
818 # - vrf:
819 # allow_vpn: true
820 # maximum:
821 # max_routes: 900
822 # max_route_options:
823 # threshold:
824 # threshold_value: 22
825 # reinstall_threshold: 44
826 # - afi: ipv6
827 # safi: unicast
828 # route_target:
829 # - import: 554832:500
830 """
831
832 RETURN = """
833 before:
834 description: The configuration prior to the module execution.
835 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
836 type: list
837 sample: >
838 This output will always be in the same format as the
839 module argspec.
840 after:
841 description: The resulting configuration after module execution.
842 returned: when changed
843 type: list
844 sample: >
845 This output will always be in the same format as the
846 module argspec.
847 commands:
848 description: The set of commands pushed to the remote device.
849 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
850 type: list
851 sample:
852 - vrf context management
853 - address-family ipv4 unicast
854 - maximum routes 500 60 reinstall 80
855 rendered:
856 description: The provided configuration in the task rendered in device-native format (offline).
857 returned: when I(state) is C(rendered)
858 type: list
859 sample:
860 - vrf context test1
861 - address-family ipv6 unicast
862 - route-target export 65512:200
863 gathered:
864 description: Facts about the network resource gathered from the remote device as structured data.
865 returned: when I(state) is C(gathered)
866 type: list
867 sample: >
868 This output will always be in the same format as the
869 module argspec.
870 parsed:
871 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
872 returned: when I(state) is C(parsed)
873 type: list
874 sample: >
875 This output will always be in the same format as the
876 module argspec.
877 """
878
879 from ansible.module_utils.basic import AnsibleModule
880
881 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.vrf_address_family.vrf_address_family import (
882 Vrf_address_familyArgs,
883 )
884 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.vrf_address_family.vrf_address_family import (
885 Vrf_address_family,
886 )
887
888
889 def main():
890 """
891 Main entry point for module execution
892
893 :returns: the result form module invocation
894 """
895 module = AnsibleModule(
896 argument_spec=Vrf_address_familyArgs.argument_spec,
897 mutually_exclusive=[["config", "running_config"]],
898 required_if=[
899 ["state", "merged", ["config"]],
900 ["state", "replaced", ["config"]],
901 ["state", "overridden", ["config"]],
902 ["state", "rendered", ["config"]],
903 ["state", "parsed", ["running_config"]],
904 ],
905 supports_check_mode=True,
906 )
907
908 result = Vrf_address_family(module).execute_module()
909 module.exit_json(**result)
910
911
912 if __name__ == "__main__":
913 main()