Debian Codegraph @

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

raw
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 iosxr_route_maps
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: iosxr_route_maps
18 short_description: Resource module to configure route maps.
19 description:
20 - This module configures and manages the attributes of Route maps on Cisco IOSXR.
21 version_added: 10.2.0
22 author: Sagar Paul (@KB-perByte)
23 notes:
24 - Tested against Cisco IOS-XR 7.2.2.
25 - This module works with connection C(network_cli).
26 options:
27 config:
28 description: A list of configurations for route policy.
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description: Name of the route policy.
34 type: str
35 global: &global
36 description: A dictionary of configurations for route policy without any conditions
37 type: dict
38 suboptions:
39 add: &add
40 description: Add offset to the existing value
41 type: dict
42 suboptions:
43 eigrp_metric:
44 description: EIGRP metric attribute
45 type: dict
46 suboptions:
47 bandwidth:
48 description: <0-4294967295> Bandwidth in Kbits per second
49 type: int
50 delay:
51 description: <0-4294967295> Delay metric in 10 microsecond units
52 type: int
53 reliability:
54 description: <0-255> Reliability metric where 255 is 100% reliable
55 type: int
56 effective_bandwith:
57 type: int
58 description: <0-255> Effective bandwidth metric (Loading) where 255 is 100% loaded
59 max_transmission:
60 description: <0-65535> Maximum Transmission Unit metric of the path
61 type: int
62 rip_metric:
63 description: <0-16> RIP metric attribute
64 type: int
65 apply: &apply
66 description: Apply a route policy
67 type: list
68 elements: dict
69 suboptions:
70 route_policy:
71 type: str
72 description: Apply a specific route policy
73 route_policy_input:
74 type: str
75 description: ipv4/ ipv6 / name-string
76 drop: &drop
77 type: bool
78 description: Reject this route with no further processing
79 pass: &pass
80 type: bool
81 description: Pass this route for further processing
82 prepend: &prepend
83 description: Prepend to BGP AS-path
84 type: dict
85 suboptions:
86 number_of_times:
87 type: int
88 description: number of times to prepend
89 as_path:
90 type: int
91 description: <1-4294967295> 32-bit decimal number/ 16-bit decimal number as-path
92 most_recent:
93 type: bool
94 description: Most recent Autonomous System Number
95 own_as:
96 type: bool
97 description: Local Autonomous System Number
98 suppress_route: &suppess
99 type: bool
100 description: Suppress specific routes when aggregating
101 unsuppress_route: &unsuppess
102 type: bool
103 description: Unsuppress specific aggregated routes
104 remove: &remove
105 description: Remove all private-as entries
106 type: dict
107 suboptions:
108 set:
109 type: bool
110 description: Remove all private-as entries (remove as-path private-as)
111 entire_aspath:
112 type: bool
113 description: Remove private-AS from entire aspath
114 set: &set
115 description: Set a route attribute
116 type: dict
117 suboptions:
118 administrative_distance:
119 description: Administrative Distance of the prefix, <1-255> 8 bit decimal numbe
120 type: int
121 local_preference:
122 description: List of local preference configurations
123 type: list
124 elements: dict
125 suboptions:
126 increment:
127 type: bool
128 description: "+ Increment the attribute with specified value"
129 decrement:
130 description: "- Decrement the attribute by specified value"
131 type: bool
132 metric_number:
133 description: "<0-4294967295> 32-bit decimal number"
134 type: int
135 required: true
136 multiply:
137 description: "* multiply the attribute by specified value"
138 type: bool
139 aigp_metric:
140 description: AIGP metric attribute
141 type: dict
142 suboptions:
143 icrement:
144 type: bool
145 description: "+ Increment the attribute with specified value"
146 decrement:
147 description: "- Decrement the attribute by specified value"
148 type: bool
149 metric_number:
150 description: <0-4294967295> 32-bit decimal number
151 type: int
152 igp_cost:
153 description: Internal routing protocol cost
154 type: bool
155 attribute_set:
156 description: TE attribute-set name <0-4294967295> 32-bit decimal number
157 type: str
158 c_multicast_routing:
159 description: Multicast Customer routing type
160 type: dict
161 suboptions:
162 bgp:
163 type: bool
164 description: BGP customer-multicast routing
165 pim:
166 type: bool
167 description: PIM customer-multicast routing
168 community:
169 description: BGP community attribute
170 type: dict
171 suboptions:
172 community_name:
173 type: str
174 description: Community set name
175 additive:
176 type: bool
177 description: Add to the existing community
178 core_tree:
179 description: Multicast Distribution Tree type
180 type: dict
181 suboptions:
182 ingress_replication:
183 type: bool
184 description: Ingress Replication core segment
185 ingress_replication_default:
186 type: bool
187 description: Ingress Replication Default MDT core
188 ingress_replication_partitioned:
189 type: bool
190 description: Ingress Replication Partitioned MDT core
191 mldp:
192 type: bool
193 description: MLDP core segment
194 mldp_default:
195 type: bool
196 description: MLDP Default MDT core
197 mldp_inband:
198 type: bool
199 description: MLDP Inband core
200 mldp_partitioned_mp2mp:
201 type: bool
202 description: MLDP Partitioned MP2MP MDT core
203 mldp_partitioned_p2mp:
204 type: bool
205 description: MLDP Partitioned P2MP MDT core
206 p2mp_te:
207 type: bool
208 description: P2MP TE core segment
209 p2mp_te_default:
210 type: bool
211 description: P2MP TE Default MDT core
212 p2mp_te_partitioned:
213 type: bool
214 description: P2MP TE Partitioned MDT core
215 pim_default:
216 type: bool
217 description: PIM Default MDT core
218 sr_p2mp:
219 type: bool
220 description: Segment-Routing P2MP core
221 dampening:
222 description: BGP route flap dampening parameters
223 type: dict
224 suboptions:
225 halflife:
226 type: int
227 description: Dampening penalty half-life, <1-45> Half-life time for penalty, default 15
228 max_suppress:
229 type: int
230 description: Maximum dampening penalty, <1-255> Maximum dampening penalty time, default 60
231 reuse:
232 type: int
233 description: Penalty before reusing suppressed route, <1-20000> Dampening reuse threshold, default 750
234 suppress:
235 type: int
236 description: Dampening penalty to start suppressing a route, <1-20000> Suppress penalty threshold, default 2000
237 downstream_core_tree:
238 description: BGP I-PMSI/S-PMSI core tree type
239 type: dict
240 suboptions:
241 ingress_replication:
242 type: bool
243 description: Ingress Replication core segment
244 mldp:
245 type: bool
246 description: MLDP core segment
247 p2mp_te:
248 type: bool
249 description: P2MP TE core segment
250 sr_p2mp:
251 type: bool
252 description: Segment-Routing P2MP core
253 eigrp_metric:
254 description: EIGRP metric attribute
255 type: dict
256 suboptions:
257 bandwidth:
258 description: <0-4294967295> Bandwidth in Kbits per second
259 type: int
260 delay:
261 description: <0-4294967295> Delay metric in 10 microsecond units
262 type: int
263 reliability:
264 description: <0-255> Reliability metric where 255 is 100% reliable
265 type: int
266 effective_bandwith:
267 type: int
268 description: <0-255> Effective bandwidth metric (Loading) where 255 is 100% loaded
269 max_transmission:
270 description: <0-65535> Maximum Transmission Unit metric of the path
271 type: int
272 extcommunity:
273 description: BGP extended community attribute
274 type: dict
275 suboptions:
276 soo:
277 description: Sub-OR-Organization
278 type: str
279 rt:
280 description: Route Target
281 type: str
282 bandwidth:
283 description: Bandwidth
284 type: str
285 color:
286 description: Color
287 type: str
288 cost:
289 description: Cost
290 type: str
291 redirect_to_rt:
292 description: Redirect to Route Target
293 type: str
294 seg_nh:
295 description: Segment Next Hop
296 type: str
297 additive:
298 description: Additive
299 type: bool
300 fallback_vrf_lookup:
301 description: fallback vrf look-up
302 type: bool
303 flow_tag:
304 description: flow tag value for PBR BGP flow-tag, <1-63> 6 bit decimal number starting from 1
305 type: int
306 forward_class:
307 description: Forward class (default value 0), <1-7> 3 bit decimal number starting from 1
308 type: int
309 ip_precedence:
310 description: IP Precedence to classify packets, <1-7> 3 bit decimal number starting from 1
311 type: int
312 isis_metric:
313 description: IS-IS metric attribute, <0-16777215> 24 bit decimal number
314 type: int
315 label:
316 description: Set BGP label value, <0-1048575> 20 bit decimal number
317 type: int
318 label_index:
319 description: Set Segment Routing label-index value, <0-1048575> 20 bit decimal number
320 type: int
321 label_mode:
322 description: Set BGP label-mode value
323 type: dict
324 suboptions:
325 per_ce:
326 type: bool
327 description: Set the label mode to per-ce
328 per_prefix:
329 type: bool
330 description: Set the label mode to per-prefix
331 per_vrf:
332 type: bool
333 description: Set the label mode to per-vrf
334 large_community:
335 description: BGP large community attribute
336 type: str
337 level:
338 description: Where to import route
339 type: dict
340 suboptions:
341 level_1:
342 type: bool
343 description: IS-IS level-1 routes
344 level_1_2:
345 type: bool
346 description: IS-IS level-1 and level-2 routes
347 level_2:
348 type: bool
349 description: IS-IS level-2 routes
350 load_balance:
351 description: Load-balance for ECMP ecmp-consistent
352 type: bool
353 lsm_root:
354 description: Label Switched Multicast Root address
355 type: str
356 metric_type:
357 description: Type of metric for destination routing protocol
358 type: dict
359 suboptions:
360 external:
361 type: bool
362 description: ISIS external metric-type
363 internal:
364 type: bool
365 description: ISIS internal metric-type
366 rib_metric_as_external:
367 type: bool
368 description: Use RIB metric and set ISIS external metric-type
369 rib_metric_as_internal:
370 type: bool
371 description: Use RIB metric and set ISIS internal metric-type
372 type_1:
373 type: bool
374 description: OSPF type-1 route
375 type_2:
376 type: bool
377 description: OSPF type-2 route
378 mpls:
379 description: MPLS traffic-eng attributeset name-string
380 type: str
381 med:
382 description: Metric for Equal-Cost Multi-Path
383 type: dict
384 suboptions:
385 value:
386 description: Metric value
387 type: int
388 increment:
389 description: Increment the metric value
390 type: int
391 decrement:
392 description: Decrement the metric value
393 type: int
394 igp_cost:
395 description: Use IGP metric
396 type: bool
397 max_reachable:
398 description: Use maximum reachable metric
399 type: bool
400 parameter:
401 description: Parameter
402 type: str
403 next_hop:
404 description: Next hop address specified in this route
405 type: dict
406 suboptions:
407 address:
408 type: str
409 description: next hop address
410 origin:
411 description: BGP origin code
412 type: dict
413 suboptions:
414 egp:
415 type: bool
416 description: ISIS external metric-type
417 igp:
418 type: bool
419 description: ISIS internal metric-type
420 rincomplete:
421 type: bool
422 description: Use RIB metric and set ISIS external metric-type
423 ospf_metric:
424 description: OSPF metric attribute
425 type: int
426 path_selection:
427 description: BGP path selection
428 type: dict
429 suboptions:
430 all:
431 type: bool
432 description: BGP all advertise
433 backup:
434 description: BGP backup
435 type: dict
436 suboptions:
437 backup_decimal:
438 type: int
439 description: <1>, decimal number 1
440 advertise:
441 type: bool
442 description: Advertise the path
443 install:
444 type: bool
445 description: Install the path
446 best_path:
447 type: bool
448 description: BGP best path
449 group_best:
450 type: bool
451 description: BGP group-best advertise
452 multiplath:
453 type: bool
454 description: BGP multipath advertise
455 path_color:
456 description: BGP Path Color for RIB (path-color external-reach)
457 type: bool
458 qos_group:
459 description: QoS Group to classify packets
460 type: int
461 rib_metric:
462 description: RIB metric for table-policy
463 type: int
464 rip_metric:
465 description: RIP metric attribute
466 type: int
467 rip_tag:
468 description: RIP Route tag attribute
469 type: int
470 rt_set:
471 description: Limit on routes with paths with an RT-set
472 type: int
473 s_pmsi:
474 description: S-PMSI Advertisement type (star-g)
475 type: bool
476 spf_priority:
477 description: OSPF SPF priority
478 type: dict
479 suboptions:
480 critical:
481 type: bool
482 description: Critical priority
483 high:
484 type: bool
485 description: High priority
486 medium:
487 type: bool
488 description: Medium priority
489 static_p2mp_te:
490 description: Static P2MP-TE tunnel
491 type: str
492 tag:
493 description: Route tag attribute
494 type: int
495 traffic_index:
496 description: Traffic-index for BGP policy accounting
497 type: dict
498 suboptions:
499 index_number:
500 type: int
501 description: 6 bit decimal number starting from 1 <1-63>
502 ignore:
503 type: bool
504 description: Remove any traffic-index setting
505 upstream_core_tree:
506 description: BGP Leaf AD core tree type
507 type: dict
508 suboptions:
509 ingress_replication:
510 type: bool
511 description: Ingress Replication core segment
512 mldp:
513 type: bool
514 description: MLDP core segment
515 p2mp_te:
516 type: bool
517 description: P2MP TE core segment
518 sr_p2mp:
519 type: bool
520 description: Segment-Routing P2MP core
521 vpn_distinguisher:
522 description: BGP VPN distinguisher (VD) attribute
523 type: int
524 weight:
525 description: Weight attribute for route selection
526 type: int
527 if_section:
528 description: A dictionary of configurations for route policy for the top level if condition for the policy
529 type: dict
530 suboptions: &ifcondition
531 condition:
532 type: str
533 description:
534 - the condition string, eg - aigp-metric eq 23 and as-path in tmp1 and
535 community is-empty and community matches-any test1 (don't add then at end)
536 add: *add
537 apply: *apply
538 drop: *drop
539 pass: *pass
540 prepend: *prepend
541 suppress_route: *suppess
542 unsuppress_route: *unsuppess
543 remove: *remove
544 set: *set
545 elseif_section: &elifmodel
546 description: A list of elif configurations that would follow along with the top level if
547 type: list
548 elements: dict
549 suboptions: *ifcondition
550 else_section:
551 description: A dictionary of configurations that would be considered in the else block
552 type: dict
553 suboptions:
554 global: *global
555 if_section:
556 description: A dictionary of configurations for route policy for the nested if condition, under top level else
557 type: dict
558 suboptions: *ifcondition
559 elseif_section: *elifmodel
560 else_section:
561 description: A dictionary of configurations for nested else, does not support if/ elseif
562 type: dict
563 suboptions:
564 add: *add
565 apply: *apply
566 drop: *drop
567 pass: *pass
568 prepend: *prepend
569 suppress_route: *suppess
570 unsuppress_route: *unsuppess
571 remove: *remove
572 set: *set
573 running_config:
574 description:
575 - This option is used only with state I(parsed).
576 - The value of this option should be and aggregate of the output received from the IOS XR
577 device by executing the command B(show running-config route-policy <policy_name>)
578 for per route-policy.
579 - The state I(parsed) reads the configuration from C(running_config) option and
580 transforms it into Ansible structured data as per the resource module's argspec
581 and the value is then returned in the I(parsed) key within the result.
582 type: str
583 state:
584 description:
585 - The state the configuration should be left in
586 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
587 on the device.
588 - The state I(rendered) will transform the configuration in C(config) option to
589 platform specific CLI commands which will be returned in the I(rendered) key
590 within the result. For state I(rendered) active connection to remote host is
591 not required.
592 - The state I(gathered) will fetch the running configuration from device and
593 transform it into structured data in the format as per the resource module
594 argspec and the value is returned in the I(gathered) key within the result.
595 - The state I(parsed) reads the configuration from C(running_config) option and
596 transforms it into JSON format as per the resource module parameters and the
597 value is returned in the I(parsed) key within the result. The value of
598 C(running_config) option should be the aggregate of the output of
599 command I(show running-config route-policy <policy_name>) that gives individual
600 route-policy details and executed on device.
601 For state I(parsed) active connection to remote host is not required.
602 type: str
603 choices:
604 - merged
605 - replaced
606 - overridden
607 - purged
608 - rendered
609 - gathered
610 - parsed
611 default: merged
612 """
613
614 EXAMPLES = """
615 # Using merged
616
617 # Before state:
618 # -------------
619 #
620 # viosxr#show running-config | include route-policy
621 #
622
623 - name: Merge route-policy configuration
624 cisco.iosxr.iosxr_route_maps:
625 state: merged
626 config:
627 - global:
628 apply:
629 - route_policy: A_NEW_ROUTE_POLICY
630 set:
631 community:
632 additive: true
633 community_name: (11011:1001)
634 weight: 20000
635 name: SIMPLE_GLOBAL_ROUTE_POLICY
636 - else_section:
637 global:
638 drop: true
639 if_section:
640 condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
641 pass: true
642 name: SIMPLE_CONDITION_ROUTE_POLICY
643 - else_section:
644 else_section:
645 drop: true
646 if_section:
647 condition: destination in A_RANDOM_POLICY
648 pass: true
649 set:
650 community:
651 additive: true
652 community_name: (101010:1)
653 if_section:
654 condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
655 drop: true
656 name: COMPLEX_ROUTE_POLICY
657 - else_section:
658 global:
659 pass: true
660 if_section:
661 condition: community matches-any (9119:1001) or community matches-any (11100:1001)
662 drop: true
663 name: COMPLEX_CONDITION_ROUTE_POLICY
664
665 # Task Output
666 # -----------
667 #
668 # before:
669 # - {}
670 # commands:
671 # - route-policy SIMPLE_GLOBAL_ROUTE_POLICY
672 # - apply A_NEW_ROUTE_POLICY
673 # - set community (11011:1001) additive
674 # - set weight 20000
675 # - end-policy
676 # - route-policy SIMPLE_CONDITION_ROUTE_POLICY
677 # - if destination in SIMPLE_CONDITION_ROUTE_POLICY then
678 # - pass
679 # - else
680 # - drop
681 # - endif
682 # - end-policy
683 # - route-policy COMPLEX_ROUTE_POLICY
684 # - if as-path in (ios-regex '_3117_', ios-regex '_600_') then
685 # - drop
686 # - else
687 # - if destination in A_RANDOM_POLICY then
688 # - pass
689 # - set community (101010:1) additive
690 # - else
691 # - drop
692 # - endif
693 # - endif
694 # - end-policy
695 # - route-policy COMPLEX_CONDITION_ROUTE_POLICY
696 # - if community matches-any (9119:1001) or community matches-any (11100:1001) then
697 # - drop
698 # - else
699 # - pass
700 # - endif
701 # - end-policy
702 # after:
703 # - global:
704 # apply:
705 # - route_policy: A_NEW_ROUTE_POLICY
706 # set:
707 # community:
708 # additive: true
709 # community_name: (11011:1001)
710 # weight: 20000
711 # name: SIMPLE_GLOBAL_ROUTE_POLICY
712 # - else_section:
713 # global:
714 # drop: true
715 # if_section:
716 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
717 # pass: true
718 # name: SIMPLE_CONDITION_ROUTE_POLICY
719 # - else_section:
720 # else_section:
721 # drop: true
722 # if_section:
723 # condition: destination in A_RANDOM_POLICY
724 # pass: true
725 # set:
726 # community:
727 # additive: true
728 # community_name: (101010:1)
729 # if_section:
730 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
731 # drop: true
732 # name: COMPLEX_ROUTE_POLICY
733 # - else_section:
734 # global:
735 # pass: true
736 # if_section:
737 # condition: community matches-any (9119:1001) or community matches-any (11100:1001)
738 # drop: true
739 # name: COMPLEX_CONDITION_ROUTE_POLICY
740
741 # After state:
742 # -------------
743 #
744 # viosxr#show running-config | include route-policy
745 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
746 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
747 # route-policy COMPLEX_ROUTE_POLICY
748 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
749 #
750 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
751 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
752 # set weight 20000
753 # set local-preference 200
754 # set community (11011:1001) additive
755 # apply A_NEW_ROUTE_POLICY
756 # end-policy
757 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
758 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
759 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
760 # pass
761 # else
762 # drop
763 # endif
764 # end-policy
765 # viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY
766 # route-policy COMPLEX_ROUTE_POLICY
767 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
768 # drop
769 # else
770 # if destination in A_RANDOM_POLICY then
771 # pass
772 # set community (101010:1) additive
773 # set local-preference 200
774 # else
775 # drop
776 # endif
777 # endif
778 # end-policy
779 # viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY
780 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
781 # if community matches-any (9119:1001) or community matches-any (11100:1001) then
782 # drop
783 # else
784 # pass
785 # endif
786 # end-policy
787
788 # Using replaced
789
790 # Before state:
791 # -------------
792 #
793 # viosxr#show running-config | include route-policy
794 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
795 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
796 # route-policy COMPLEX_ROUTE_POLICY
797 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
798 #
799 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
800 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
801 # set weight 20000
802 # set local-preference 200
803 # set community (11011:1001) additive
804 # apply A_NEW_ROUTE_POLICY
805 # end-policy
806 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
807 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
808 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
809 # pass
810 # else
811 # drop
812 # endif
813 # end-policy
814 # viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY
815 # route-policy COMPLEX_ROUTE_POLICY
816 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
817 # drop
818 # else
819 # if destination in A_RANDOM_POLICY then
820 # pass
821 # set community (101010:1) additive
822 # set local-preference 200
823 # else
824 # drop
825 # endif
826 # endif
827 # end-policy
828 # viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY
829 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
830 # if community matches-any (9119:1001) or community matches-any (11100:1001) then
831 # drop
832 # else
833 # pass
834 # endif
835 # end-policy
836
837 - name: Replace the route-policy configuration
838 cisco.iosxr.iosxr_route_maps:
839 state: replaced
840 config:
841 - global:
842 apply:
843 - route_policy: A_NEW_ROUTE_POLICY
844 set:
845 community:
846 additive: true
847 community_name: (11011:1001)
848 weight: 20000
849 name: SIMPLE_GLOBAL_ROUTE_POLICY
850 - else_section:
851 global:
852 drop: true
853 if_section:
854 condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
855 pass: true
856 name: VERY_SIMPLE_CONDITION_ROUTE_POLICY
857
858 # Task Output
859 # -----------
860 #
861 # before:
862 # - global:
863 # apply:
864 # - route_policy: A_NEW_ROUTE_POLICY
865 # set:
866 # community:
867 # additive: true
868 # community_name: (11011:1001)
869 # weight: 20000
870 # name: SIMPLE_GLOBAL_ROUTE_POLICY
871 # - else_section:
872 # global:
873 # drop: true
874 # if_section:
875 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
876 # pass: true
877 # name: SIMPLE_CONDITION_ROUTE_POLICY
878 # - else_section:
879 # else_section:
880 # drop: true
881 # if_section:
882 # condition: destination in A_RANDOM_POLICY
883 # pass: true
884 # set:
885 # community:
886 # additive: true
887 # community_name: (101010:1)
888 # if_section:
889 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
890 # drop: true
891 # name: COMPLEX_ROUTE_POLICY
892 # - else_section:
893 # global:
894 # pass: true
895 # if_section:
896 # condition: community matches-any (9119:1001) or community matches-any (11100:1001)
897 # drop: true
898 # name: COMPLEX_CONDITION_ROUTE_POLICY
899 # commands:
900 # - route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
901 # - if destination in SIMPLE_CONDITION_ROUTE_POLICY then
902 # - pass
903 # - else
904 # - drop
905 # - endif
906 # - end-policy
907 # after:
908 # - global:
909 # apply:
910 # - route_policy: A_NEW_ROUTE_POLICY
911 # set:
912 # community:
913 # additive: true
914 # community_name: (11011:1001)
915 # weight: 20000
916 # name: SIMPLE_GLOBAL_ROUTE_POLICY
917 # - else_section:
918 # global:
919 # drop: true
920 # if_section:
921 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
922 # pass: true
923 # name: SIMPLE_CONDITION_ROUTE_POLICY
924 # - else_section:
925 # else_section:
926 # drop: true
927 # if_section:
928 # condition: destination in A_RANDOM_POLICY
929 # pass: true
930 # set:
931 # community:
932 # additive: true
933 # community_name: (101010:1)
934 # if_section:
935 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
936 # drop: true
937 # name: COMPLEX_ROUTE_POLICY
938 # - else_section:
939 # global:
940 # pass: true
941 # if_section:
942 # condition: community matches-any (9119:1001) or community matches-any (11100:1001)
943 # drop: true
944 # name: COMPLEX_CONDITION_ROUTE_POLICY
945 # - else_section:
946 # global:
947 # drop: true
948 # if_section:
949 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
950 # pass: true
951 # name: VERY_SIMPLE_CONDITION_ROUTE_POLICY
952
953 # After state:
954 # -------------
955 #
956 # viosxr#show running-config | include route-policy
957 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
958 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
959 # route-policy COMPLEX_ROUTE_POLICY
960 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
961 # route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
962 #
963 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
964 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
965 # set weight 20000
966 # set local-preference 200
967 # set community (11011:1001) additive
968 # apply A_NEW_ROUTE_POLICY
969 # end-policy
970 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
971 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
972 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
973 # pass
974 # else
975 # drop
976 # endif
977 # end-policy
978 # viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY
979 # route-policy COMPLEX_ROUTE_POLICY
980 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
981 # drop
982 # else
983 # if destination in A_RANDOM_POLICY then
984 # pass
985 # set community (101010:1) additive
986 # set local-preference 200
987 # else
988 # drop
989 # endif
990 # endif
991 # end-policy
992 # viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY
993 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
994 # if community matches-any (9119:1001) or community matches-any (11100:1001) then
995 # drop
996 # else
997 # pass
998 # endif
999 # end-policy
1000 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
1001 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1002 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1003 # pass
1004 # else
1005 # drop
1006 # endif
1007 # end-policy
1008 # viosxr#show running-config route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
1009 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1010 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1011 # pass
1012 # else
1013 # drop
1014 # endif
1015 # end-policy
1016
1017 # Using overridden
1018
1019 # Before state:
1020 # -------------
1021 #
1022 # viosxr#show running-config | include route-policy
1023 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1024 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1025 # route-policy COMPLEX_ROUTE_POLICY
1026 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
1027 #
1028 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1029 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1030 # set weight 20000
1031 # set local-preference 200
1032 # set community (11011:1001) additive
1033 # apply A_NEW_ROUTE_POLICY
1034 # end-policy
1035 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
1036 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1037 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1038 # pass
1039 # else
1040 # drop
1041 # endif
1042 # end-policy
1043 # viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY
1044 # route-policy COMPLEX_ROUTE_POLICY
1045 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
1046 # drop
1047 # else
1048 # if destination in A_RANDOM_POLICY then
1049 # pass
1050 # set community (101010:1) additive
1051 # set local-preference 200
1052 # else
1053 # drop
1054 # endif
1055 # endif
1056 # end-policy
1057 # viosxr#show running-config route-policy COMPLEX_CONDITION_ROUTE_POLICY
1058 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
1059 # if community matches-any (9119:1001) or community matches-any (11100:1001) then
1060 # drop
1061 # else
1062 # pass
1063 # endif
1064 # end-policy
1065
1066 - name: Override the route-policy configuration
1067 cisco.iosxr.iosxr_route_maps:
1068 state: overridden
1069 config:
1070 - global:
1071 apply:
1072 - route_policy: A_NEW_ROUTE_POLICY
1073 set:
1074 community:
1075 additive: true
1076 community_name: (11011:1001)
1077 weight: 20000
1078 name: SIMPLE_GLOBAL_ROUTE_POLICY
1079 - else_section:
1080 global:
1081 drop: true
1082 if_section:
1083 condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1084 pass: true
1085 name: VERY_SIMPLE_CONDITION_ROUTE_POLICY
1086
1087 # Task Output
1088 # -----------
1089 #
1090 # before:
1091 # - global:
1092 # apply:
1093 # - route_policy: A_NEW_ROUTE_POLICY
1094 # set:
1095 # community:
1096 # additive: true
1097 # community_name: (11011:1001)
1098 # weight: 20000
1099 # name: SIMPLE_GLOBAL_ROUTE_POLICY
1100 # - else_section:
1101 # global:
1102 # drop: true
1103 # if_section:
1104 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1105 # pass: true
1106 # name: SIMPLE_CONDITION_ROUTE_POLICY
1107 # - else_section:
1108 # else_section:
1109 # drop: true
1110 # if_section:
1111 # condition: destination in A_RANDOM_POLICY
1112 # pass: true
1113 # set:
1114 # community:
1115 # additive: true
1116 # community_name: (101010:1)
1117 # if_section:
1118 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
1119 # drop: true
1120 # name: COMPLEX_ROUTE_POLICY
1121 # - else_section:
1122 # global:
1123 # pass: true
1124 # if_section:
1125 # condition: community matches-any (9119:1001) or community matches-any (11100:1001)
1126 # drop: true
1127 # name: COMPLEX_CONDITION_ROUTE_POLICY
1128 # commands:
1129 # - route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
1130 # - if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1131 # - pass
1132 # - else
1133 # - drop
1134 # - endif
1135 # - end-policy
1136 # - no route-policy SIMPLE_CONDITION_ROUTE_POLICY
1137 # - no route-policy COMPLEX_ROUTE_POLICY
1138 # - no route-policy COMPLEX_CONDITION_ROUTE_POLICY
1139 # after:
1140 # - global:
1141 # apply:
1142 # - route_policy: A_NEW_ROUTE_POLICY
1143 # set:
1144 # community:
1145 # additive: true
1146 # community_name: (11011:1001)
1147 # weight: 20000
1148 # name: SIMPLE_GLOBAL_ROUTE_POLICY
1149 # - else_section:
1150 # global:
1151 # drop: true
1152 # if_section:
1153 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1154 # pass: true
1155 # name: VERY_SIMPLE_CONDITION_ROUTE_POLICY
1156
1157 # After state:
1158 # -------------
1159 #
1160 # viosxr#show running-config | include route-policy
1161 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1162 # route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
1163 #
1164 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1165 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1166 # set weight 20000
1167 # set local-preference 200
1168 # set community (11011:1001) additive
1169 # apply A_NEW_ROUTE_POLICY
1170 # end-policy
1171 # viosxr#show running-config route-policy VERY_SIMPLE_CONDITION_ROUTE_POLICY
1172 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1173 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1174 # pass
1175 # else
1176 # drop
1177 # endif
1178 # end-policy
1179
1180 # Using purged
1181
1182 # Before state:
1183 # -------------
1184 #
1185 # viosxr#show running-config | include route-policy
1186 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1187 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1188 # route-policy COMPLEX_ROUTE_POLICY
1189 #
1190 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1191 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1192 # set weight 20000
1193 # set local-preference 200
1194 # set community (11011:1001) additive
1195 # apply A_NEW_ROUTE_POLICY
1196 # end-policy
1197 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
1198 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1199 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1200 # pass
1201 # else
1202 # drop
1203 # endif
1204 # end-policy
1205 # viosxr#show running-config route-policy COMPLEX_ROUTE_POLICY
1206 # route-policy COMPLEX_ROUTE_POLICY
1207 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
1208 # drop
1209 # else
1210 # if destination in A_RANDOM_POLICY then
1211 # pass
1212 # set community (101010:1) additive
1213 # set local-preference 200
1214 # else
1215 # drop
1216 # endif
1217 # endif
1218 # end-policy
1219
1220 - name: Purge or remove route-policy configuration
1221 cisco.iosxr.iosxr_route_maps:
1222 state: purged
1223 config:
1224 - name: COMPLEX_ROUTE_POLICY_NO_EXIST
1225 - name: COMPLEX_ROUTE_POLICY
1226
1227 # Task Output
1228 # -----------
1229 #
1230 # before:
1231 # - global:
1232 # apply:
1233 # - route_policy: A_NEW_ROUTE_POLICY
1234 # set:
1235 # community:
1236 # additive: true
1237 # community_name: (11011:1001)
1238 # weight: 20000
1239 # name: SIMPLE_GLOBAL_ROUTE_POLICY
1240 # - else_section:
1241 # global:
1242 # drop: true
1243 # if_section:
1244 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1245 # pass: true
1246 # name: SIMPLE_CONDITION_ROUTE_POLICY
1247 # - else_section:
1248 # else_section:
1249 # drop: true
1250 # if_section:
1251 # condition: destination in A_RANDOM_POLICY
1252 # pass: true
1253 # set:
1254 # community:
1255 # additive: true
1256 # community_name: (101010:1)
1257 # if_section:
1258 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
1259 # drop: true
1260 # name: COMPLEX_ROUTE_POLICY
1261 # commands:
1262 # - no route-policy COMPLEX_CONDITION_ROUTE_POLICY
1263 # after:
1264 # - global:
1265 # apply:
1266 # - route_policy: A_NEW_ROUTE_POLICY
1267 # set:
1268 # community:
1269 # additive: true
1270 # community_name: (11011:1001)
1271 # weight: 20000
1272 # name: SIMPLE_GLOBAL_ROUTE_POLICY
1273 # - else_section:
1274 # global:
1275 # drop: true
1276 # if_section:
1277 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1278 # pass: true
1279 # name: SIMPLE_CONDITION_ROUTE_POLICY
1280
1281 # After state:
1282 # -------------
1283 #
1284 # viosxr#show running-config | include route-policy
1285 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1286 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1287 #
1288 # viosxr#show running-config route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1289 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1290 # set weight 20000
1291 # set local-preference 200
1292 # set community (11011:1001) additive
1293 # apply A_NEW_ROUTE_POLICY
1294 # end-policy
1295 # viosxr#show running-config route-policy SIMPLE_CONDITION_ROUTE_POLICY
1296 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1297 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1298 # pass
1299 # else
1300 # drop
1301 # endif
1302 # end-policy
1303
1304 # Using rendered
1305
1306 - name: Render route-policy configuration
1307 cisco.iosxr.iosxr_route_maps:
1308 state: rendered
1309 config:
1310 - global:
1311 apply:
1312 - route_policy: A_NEW_ROUTE_POLICY
1313 set:
1314 community:
1315 additive: true
1316 community_name: (11011:1001)
1317 weight: 20000
1318 name: SIMPLE_GLOBAL_ROUTE_POLICY
1319 - else_section:
1320 global:
1321 drop: true
1322 if_section:
1323 condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1324 pass: true
1325 name: SIMPLE_CONDITION_ROUTE_POLICY
1326 - else_section:
1327 else_section:
1328 drop: true
1329 if_section:
1330 condition: destination in A_RANDOM_POLICY
1331 pass: true
1332 set:
1333 community:
1334 additive: true
1335 community_name: (101010:1)
1336 if_section:
1337 condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
1338 drop: true
1339 name: COMPLEX_ROUTE_POLICY
1340 - else_section:
1341 global:
1342 pass: true
1343 if_section:
1344 condition: community matches-any (9119:1001) or community matches-any (11100:1001)
1345 drop: true
1346 name: COMPLEX_CONDITION_ROUTE_POLICY
1347
1348 # Task Output
1349 # -----------
1350 #
1351 # rendered:
1352 # - route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1353 # - apply A_NEW_ROUTE_POLICY
1354 # - set community (11011:1001) additive
1355 # - set weight 20000
1356 # - end-policy
1357 # - route-policy SIMPLE_CONDITION_ROUTE_POLICY
1358 # - if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1359 # - pass
1360 # - else
1361 # - drop
1362 # - endif
1363 # - end-policy
1364 # - route-policy COMPLEX_ROUTE_POLICY
1365 # - if as-path in (ios-regex '_3117_', ios-regex '_600_') then
1366 # - drop
1367 # - else
1368 # - if destination in A_RANDOM_POLICY then
1369 # - pass
1370 # - set community (101010:1) additive
1371 # - else
1372 # - drop
1373 # - endif
1374 # - endif
1375 # - end-policy
1376 # - route-policy COMPLEX_CONDITION_ROUTE_POLICY
1377 # - if community matches-any (9119:1001) or community matches-any (11100:1001) then
1378 # - drop
1379 # - else
1380 # - pass
1381 # - endif
1382 # - end-policy
1383
1384 # Using parsed
1385
1386 # File: parsed.cfg
1387 # ----------------
1388 #
1389 # route-policy SIMPLE_GLOBAL_ROUTE_POLICY
1390 # set weight 20000
1391 # set local-preference 200
1392 # set community (11011:1001) additive
1393 # apply A_NEW_ROUTE_POLICY
1394 # end-policy
1395 # !
1396 # route-policy SIMPLE_CONDITION_ROUTE_POLICY
1397 # if destination in SIMPLE_CONDITION_ROUTE_POLICY then
1398 # pass
1399 # else
1400 # drop
1401 # endif
1402 # end-policy
1403 # !
1404 # route-policy COMPLEX_ROUTE_POLICY
1405 # if as-path in (ios-regex '_3117_', ios-regex '_600_') then
1406 # drop
1407 # else
1408 # if destination in A_RANDOM_POLICY then
1409 # pass
1410 # set community (101010:1) additive
1411 # set local-preference 200
1412 # else
1413 # drop
1414 # endif
1415 # endif
1416 # end-policy
1417 # !
1418 # route-policy COMPLEX_CONDITION_ROUTE_POLICY
1419 # if community matches-any (9119:1001) or community matches-any (11100:1001) then
1420 # drop
1421 # else
1422 # pass
1423 # endif
1424 # end-policy
1425
1426 - name: Parse the provided configuration
1427 cisco.iosxr.iosxr_route_maps:
1428 running_config: "{{ lookup('file', 'iosxr_route_maps_conf.cfg') }}"
1429 state: parsed
1430
1431 # Task Output
1432 # -----------
1433 #
1434 # parsed:
1435 # - global:
1436 # apply:
1437 # - route_policy: A_NEW_ROUTE_POLICY
1438 # set:
1439 # community:
1440 # additive: true
1441 # community_name: (11011:1001)
1442 # weight: 20000
1443 # name: SIMPLE_GLOBAL_ROUTE_POLICY
1444 # - else_section:
1445 # global:
1446 # drop: true
1447 # if_section:
1448 # condition: destination in SIMPLE_CONDITION_ROUTE_POLICY
1449 # pass: true
1450 # name: SIMPLE_CONDITION_ROUTE_POLICY
1451 # - else_section:
1452 # else_section:
1453 # drop: true
1454 # if_section:
1455 # condition: destination in A_RANDOM_POLICY
1456 # pass: true
1457 # set:
1458 # community:
1459 # additive: true
1460 # community_name: (101010:1)
1461 # if_section:
1462 # condition: as-path in (ios-regex '_3117_', ios-regex '_600_')
1463 # drop: true
1464 # name: COMPLEX_ROUTE_POLICY
1465 # - else_section:
1466 # global:
1467 # pass: true
1468 # if_section:
1469 # condition: community matches-any (9119:1001) or community matches-any (11100:1001)
1470 # drop: true
1471 # name: COMPLEX_CONDITION_ROUTE_POLICY
1472 """
1473
1474 RETURN = """
1475 before:
1476 description: The configuration prior to the module execution.
1477 returned: when I(state) is C(merged), C(replaced), C(overridden), C(purged) or C(purged)
1478 type: dict
1479 sample: >
1480 This output will always be in the same format as the
1481 module argspec.
1482 after:
1483 description: The resulting configuration after module execution.
1484 returned: when changed
1485 type: dict
1486 sample: >
1487 This output will always be in the same format as the
1488 module argspec.
1489 commands:
1490 description: The set of commands pushed to the remote device.
1491 returned: when I(state) is C(merged), C(replaced), C(overridden), C(purged) or C(purged)
1492 type: list
1493 sample:
1494 - route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX
1495 - if destination in DEFAULT then
1496 - pass
1497 rendered:
1498 description: The provided configuration in the task rendered in device-native format (offline).
1499 returned: when I(state) is C(rendered)
1500 type: list
1501 sample:
1502 - route-policy APPLY_TEST_ROUTE_POLICY_COMPLEX
1503 - if destination in DEFAULT then
1504 - pass
1505 gathered:
1506 description: Facts about the network resource gathered from the remote device as structured data.
1507 returned: when I(state) is C(gathered)
1508 type: list
1509 sample: >
1510 This output will always be in the same format as the
1511 module argspec.
1512 parsed:
1513 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
1514 returned: when I(state) is C(parsed)
1515 type: list
1516 sample: >
1517 This output will always be in the same format as the
1518 module argspec.
1519 """
1520
1521 from ansible.module_utils.basic import AnsibleModule
1522
1523 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.route_maps.route_maps import (
1524 Route_mapsArgs,
1525 )
1526 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.config.route_maps.route_maps import (
1527 Route_maps,
1528 )
1529
1530
1531 def main():
1532 """
1533 Main entry point for module execution
1534
1535 :returns: the result form module invocation
1536 """
1537 module = AnsibleModule(
1538 argument_spec=Route_mapsArgs.argument_spec,
1539 mutually_exclusive=[["config", "running_config"]],
1540 required_if=[
1541 ["state", "merged", ["config"]],
1542 ["state", "replaced", ["config"]],
1543 ["state", "overridden", ["config"]],
1544 ["state", "rendered", ["config"]],
1545 ["state", "parsed", ["running_config"]],
1546 ],
1547 supports_check_mode=True,
1548 )
1549
1550 result = Route_maps(module).execute_module()
1551 module.exit_json(**result)
1552
1553
1554 if __name__ == "__main__":
1555 main()