Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2021 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_prefix_lists
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: nxos_prefix_lists
18 short_description: Prefix-Lists resource module.
19 description:
20 - This module manages prefix-lists configuration on devices running Cisco NX-OS.
21 version_added: 2.4.0
22 notes:
23 - Tested against NX-OS 9.3.6.
24 - Unsupported for Cisco MDS
25 - This module works with connection C(network_cli) and C(httpapi).
26 author: Nilashish Chakraborty (@NilashishC)
27 options:
28 running_config:
29 description:
30 - This option is used only with state I(parsed).
31 - The value of this option should be the output received from the NX-OS device
32 by executing the command B(show running-config | section '^ip(.*) prefix-list').
33 - The state I(parsed) reads the configuration from C(running_config) option and
34 transforms it into Ansible structured data as per the resource module's argspec
35 and the value is then returned in the I(parsed) key within the result.
36 type: str
37 config:
38 description: A list of prefix-list configuration.
39 type: list
40 elements: dict
41 suboptions:
42 afi:
43 description:
44 - The Address Family Identifier (AFI) for the prefix-lists.
45 type: str
46 choices: ["ipv4", "ipv6"]
47 prefix_lists:
48 description: List of prefix-list configurations.
49 type: list
50 elements: dict
51 suboptions:
52 name:
53 description: Name of the prefix-list.
54 type: str
55 description:
56 description: Description of the prefix list
57 type: str
58 entries:
59 description: List of configurations for the specified prefix-list
60 type: list
61 elements: dict
62 suboptions:
63 sequence:
64 description: Sequence Number.
65 type: int
66 action:
67 description: Prefix-List permit or deny.
68 type: str
69 choices: ["permit", "deny"]
70 prefix:
71 description: IP or IPv6 prefix in A.B.C.D/LEN or A:B::C:D/LEN format.
72 type: str
73 eq:
74 description: Exact prefix length to be matched.
75 type: int
76 ge:
77 description: Minimum prefix length to be matched.
78 type: int
79 le:
80 description: Maximum prefix length to be matched.
81 type: int
82 mask:
83 description: Explicit match mask.
84 type: str
85 state:
86 description:
87 - The state the configuration should be left in.
88 - Refer to examples for more details.
89 - With state I(replaced), for the listed prefix-lists,
90 sequences that are in running-config but not in the task are negated.
91 - With state I(overridden), all prefix-lists that are in running-config but
92 not in the task are negated.
93 - Please refer to examples for more details.
94 type: str
95 choices:
96 - merged
97 - replaced
98 - overridden
99 - deleted
100 - parsed
101 - gathered
102 - rendered
103 default: merged
104 """
105 EXAMPLES = """
106 # Using merged
107
108 # Before state:
109 # -------------
110 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
111 # nxos-9k-rdo#
112
113 - name: Merge the provided configuration with the existing running configuration
114 cisco.nxos.nxos_prefix_lists:
115 config:
116 - afi: ipv4
117 prefix_lists:
118 - name: AllowPrefix
119 description: allows engineering IPv4 networks
120 entries:
121 - sequence: 10
122 action: permit
123 prefix: 192.0.2.0/23
124 eq: 24
125 - sequence: 20
126 action: permit
127 prefix: 198.51.100.128/26
128 - name: DenyPrefix
129 description: denies lab IPv4 networks
130 entries:
131 - sequence: 20
132 action: deny
133 prefix: 203.0.113.0/24
134 le: 25
135
136 - afi: ipv6
137 prefix_lists:
138 - name: AllowIPv6Prefix
139 description: allows engineering IPv6 networks
140 entries:
141 - sequence: 8
142 action: permit
143 prefix: "2001:db8:400::/38"
144 - sequence: 20
145 action: permit
146 prefix: "2001:db8:8000::/35"
147 le: 37
148
149 # Task output
150 # -------------
151 # before: []
152 #
153 # commands:
154 # - "ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks"
155 # - "ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38"
156 # - "ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37"
157 # - "ip prefix-list AllowPrefix description allows engineering IPv4 networks"
158 # - "ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24"
159 # - "ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26"
160 # - "ip prefix-list DenyPrefix description denies lab IPv4 networks"
161 # - "ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25"
162 #
163 # after:
164 # - afi: ipv4
165 # prefix_lists:
166 # - description: allows engineering IPv4 networks
167 # entries:
168 # - sequence: 10
169 # action: permit
170 # prefix: 192.0.2.0/23
171 # eq: 24
172 # - sequence: 20
173 # action: permit
174 # prefix: 198.51.100.128/26
175 # name: AllowPrefix
176 # - description: denies lab IPv4 networks
177 # entries:
178 # - sequence: 20
179 # action: deny
180 # prefix: 203.0.113.0/24
181 # le: 25
182 # name: DenyPrefix
183 #
184 # - afi: ipv6
185 # prefix_lists:
186 # - description: allows engineering IPv6 networks
187 # entries:
188 # - sequence: 8
189 # action: permit
190 # prefix: "2001:db8:400::/38"
191 # - sequence: 20
192 # action: permit
193 # prefix: "2001:db8:8000::/35"
194 # le: 37
195 # name: AllowIPv6Prefix
196
197 # After state:
198 # ------------
199 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
200 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
201 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
202 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
203 # ip prefix-list DenyPrefix description denies lab IPv4 networks
204 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
205 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
206 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
207 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
208
209 # Using replaced
210
211 # Before state:
212 # ------------
213 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
214 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
215 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
216 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
217 # ip prefix-list DenyPrefix description denies lab IPv4 networks
218 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
219 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
220 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
221 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
222
223 - name: Replace prefix-lists configurations of listed prefix-lists with provided configurations
224 cisco.nxos.nxos_prefix_lists:
225 config:
226 - afi: ipv4
227 prefix_lists:
228 - name: AllowPrefix
229 description: allows engineering IPv4 networks
230 entries:
231 - sequence: 10
232 action: permit
233 prefix: 203.0.113.64/27
234
235 - sequence: 30
236 action: permit
237 prefix: 203.0.113.96/27
238 - name: AllowPrefix2Stub
239 description: allow other engineering IPv4 network
240 state: replaced
241
242 # Task output
243 # -------------
244 # before:
245 # - afi: ipv4
246 # prefix_lists:
247 # - description: allows engineering IPv4 networks
248 # entries:
249 # - sequence: 10
250 # action: permit
251 # prefix: 192.0.2.0/23
252 # eq: 24
253 # - sequence: 20
254 # action: permit
255 # prefix: 198.51.100.128/26
256 # name: AllowPrefix
257 # - description: denies lab IPv4 networks
258 # entries:
259 # - sequence: 20
260 # action: deny
261 # prefix: 203.0.113.0/24
262 # le: 25
263 # name: DenyPrefix
264 #
265 # - afi: ipv6
266 # prefix_lists:
267 # - description: allows engineering IPv6 networks
268 # entries:
269 # - sequence: 8
270 # action: permit
271 # prefix: "2001:db8:400::/38"
272 # - sequence: 20
273 # action: permit
274 # prefix: "2001:db8:8000::/35"
275 # le: 37
276 # name: AllowIPv6Prefix
277 #
278 # commands:
279 # - "no ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24"
280 # - "ip prefix-list AllowPrefix seq 10 permit 203.0.113.64/27"
281 # - "ip prefix-list AllowPrefix seq 30 permit 203.0.113.96/27"
282 # - "no ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26"
283 # - "ip prefix-list AllowPrefix2Stub description allow other engineering IPv4 network"
284 #
285 # after:
286 # - afi: ipv4
287 # prefix_lists:
288 # - description: allows engineering IPv4 networks
289 # entries:
290 # - sequence: 10
291 # action: permit
292 # prefix: 203.0.113.64/27
293 # - sequence: 30
294 # action: permit
295 # prefix: 203.0.113.96/27
296 # name: AllowPrefix
297 # - description: allow other engineering IPv4 network
298 # name: AllowPrefix2Stub
299 # - description: denies lab IPv4 networks
300 # entries:
301 # - sequence: 20
302 # action: deny
303 # prefix: 203.0.113.0/24
304 # le: 25
305 # name: DenyPrefix
306 #
307 # - afi: ipv6
308 # prefix_lists:
309 # - description: allows engineering IPv6 networks
310 # entries:
311 # - sequence: 8
312 # action: permit
313 # prefix: "2001:db8:400::/38"
314 # - sequence: 20
315 # action: permit
316 # prefix: "2001:db8:8000::/35"
317 # le: 37
318 # name: AllowIPv6Prefix
319 #
320 # After state:
321 # ------------
322 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
323 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
324 # ip prefix-list AllowPrefix seq 10 permit 203.0.113.64/27
325 # ip prefix-list AllowPrefix seq 30 permit 203.0.113.96/27
326 # ip prefix-list AllowPrefix2Stub description allow other engineering IPv4 network
327 # ip prefix-list DenyPrefix description denies lab IPv4 networks
328 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
329 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
330 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
331 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
332
333 # Using overridden
334
335 # Before state:
336 # ------------
337 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
338 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
339 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
340 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
341 # ip prefix-list DenyPrefix description denies lab IPv4 networks
342 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
343 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
344 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
345 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
346
347 - name: Override all prefix-lists configuration with provided configuration
348 cisco.nxos.nxos_prefix_lists: &id003
349 config:
350 - afi: ipv4
351 prefix_lists:
352 - name: AllowPrefix
353 description: allows engineering IPv4 networks
354 entries:
355 - sequence: 10
356 action: permit
357 prefix: 203.0.113.64/27
358
359 - sequence: 30
360 action: permit
361 prefix: 203.0.113.96/27
362 - name: AllowPrefix2Stub
363 description: allow other engineering IPv4 network
364 state: overridden
365
366 # Task output
367 # -------------
368 # before:
369 # - afi: ipv4
370 # prefix_lists:
371 # - description: allows engineering IPv4 networks
372 # entries:
373 # - sequence: 10
374 # action: permit
375 # prefix: 192.0.2.0/23
376 # eq: 24
377 # - sequence: 20
378 # action: permit
379 # prefix: 198.51.100.128/26
380 # name: AllowPrefix
381 # - description: denies lab IPv4 networks
382 # entries:
383 # - sequence: 20
384 # action: deny
385 # prefix: 203.0.113.0/24
386 # le: 25
387 # name: DenyPrefix
388 #
389 # - afi: ipv6
390 # prefix_lists:
391 # - description: allows engineering IPv6 networks
392 # entries:
393 # - sequence: 8
394 # action: permit
395 # prefix: "2001:db8:400::/38"
396 # - sequence: 20
397 # action: permit
398 # prefix: "2001:db8:8000::/35"
399 # le: 37
400 # name: AllowIPv6Prefix
401 #
402 # commands:
403 # - "no ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24"
404 # - "ip prefix-list AllowPrefix seq 10 permit 203.0.113.64/27"
405 # - "ip prefix-list AllowPrefix seq 30 permit 203.0.113.96/27"
406 # - "no ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26"
407 # - "ip prefix-list AllowPrefix2Stub description allow other engineering IPv4 network"
408 # - "no ip prefix-list DenyPrefix"
409 # - "no ipv6 prefix-list AllowIPv6Prefix"
410 #
411 # after:
412 # - afi: ipv4
413 # prefix_lists:
414 # - name: AllowPrefix
415 # description: allows engineering IPv4 networks
416 # entries:
417 # - sequence: 10
418 # action: permit
419 # prefix: 203.0.113.64/27
420 #
421 # - sequence: 30
422 # action: permit
423 # prefix: 203.0.113.96/27
424 # - name: AllowPrefix2Stub
425 # description: allow other engineering IPv4 network
426 #
427 # After state:
428 # ------------
429 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
430 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
431 # ip prefix-list AllowPrefix seq 10 permit 203.0.113.64/27
432 # ip prefix-list AllowPrefix seq 30 permit 203.0.113.96/27
433 # ip prefix-list AllowPrefix2Stub description allow other engineering IPv4 network
434
435 # Using deleted to delete a all prefix lists for an AFI
436
437 # Before state:
438 # ------------
439 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
440 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
441 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
442 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
443 # ip prefix-list DenyPrefix description denies lab IPv4 networks
444 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
445 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
446 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
447 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
448
449 - name: Delete all prefix-lists for an AFI
450 cisco.nxos.nxos_prefix_lists:
451 config:
452 - afi: ipv4
453 state: deleted
454 register: result
455
456 # Task output
457 # -------------
458 # before:
459 # - afi: ipv4
460 # prefix_lists:
461 # - description: allows engineering IPv4 networks
462 # entries:
463 # - sequence: 10
464 # action: permit
465 # prefix: 192.0.2.0/23
466 # eq: 24
467 # - sequence: 20
468 # action: permit
469 # prefix: 198.51.100.128/26
470 # name: AllowPrefix
471 # - description: denies lab IPv4 networks
472 # entries:
473 # - sequence: 20
474 # action: deny
475 # prefix: 203.0.113.0/24
476 # le: 25
477 # name: DenyPrefix
478 #
479 # - afi: ipv6
480 # prefix_lists:
481 # - description: allows engineering IPv6 networks
482 # entries:
483 # - sequence: 8
484 # action: permit
485 # prefix: "2001:db8:400::/38"
486 # - sequence: 20
487 # action: permit
488 # prefix: "2001:db8:8000::/35"
489 # le: 37
490 # name: AllowIPv6Prefix
491 #
492 # commands:
493 # - "no ip prefix-list AllowPrefix"
494 # - "no ip prefix-list DenyPrefix"
495 #
496 # after:
497 # - afi: ipv6
498 # prefix_lists:
499 # - description: allows engineering IPv6 networks
500 # entries:
501 # - sequence: 8
502 # action: permit
503 # prefix: "2001:db8:400::/38"
504 # - sequence: 20
505 # action: permit
506 # prefix: "2001:db8:8000::/35"
507 # le: 37
508 # name: AllowIPv6Prefix
509 #
510 # After state:
511 # ------------
512 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
513 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
514 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
515 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
516
517 # Using deleted to delete a single prefix-list
518
519 # Before state:
520 # ------------
521 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
522 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
523 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
524 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
525 # ip prefix-list DenyPrefix description denies lab IPv4 networks
526 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
527 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
528 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
529 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
530
531 - name: Delete a single prefix-list
532 cisco.nxos.nxos_prefix_lists:
533 config:
534 - afi: ipv4
535 prefix_lists:
536 - name: AllowPrefix
537 state: deleted
538
539 # Task output
540 # -------------
541 # before:
542 # - afi: ipv4
543 # prefix_lists:
544 # - description: allows engineering IPv4 networks
545 # entries:
546 # - sequence: 10
547 # action: permit
548 # prefix: 192.0.2.0/23
549 # eq: 24
550 # - sequence: 20
551 # action: permit
552 # prefix: 198.51.100.128/26
553 # name: AllowPrefix
554 # - description: denies lab IPv4 networks
555 # entries:
556 # - sequence: 20
557 # action: deny
558 # prefix: 203.0.113.0/24
559 # le: 25
560 # name: DenyPrefix
561 #
562 # - afi: ipv6
563 # prefix_lists:
564 # - description: allows engineering IPv6 networks
565 # entries:
566 # - sequence: 8
567 # action: permit
568 # prefix: "2001:db8:400::/38"
569 # - sequence: 20
570 # action: permit
571 # prefix: "2001:db8:8000::/35"
572 # le: 37
573 # name: AllowIPv6Prefix
574 #
575 # commands:
576 # - "no ip prefix-list AllowPrefix"
577 #
578 # after:
579 # - afi: ipv4
580 # prefix_lists:
581 # - description: denies lab IPv4 networks
582 # entries:
583 # - sequence: 20
584 # action: deny
585 # prefix: 203.0.113.0/24
586 # le: 25
587 # name: DenyPrefix
588 #
589 # - afi: ipv6
590 # prefix_lists:
591 # - description: allows engineering IPv6 networks
592 # entries:
593 # - sequence: 8
594 # action: permit
595 # prefix: "2001:db8:400::/38"
596 # - sequence: 20
597 # action: permit
598 # prefix: "2001:db8:8000::/35"
599 # le: 37
600 # name: AllowIPv6Prefix
601 #
602 # After state:
603 # ------------
604 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
605 # ip prefix-list DenyPrefix description denies lab IPv4 networks
606 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
607 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
608 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
609 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
610
611 # Using deleted to delete all prefix-lists from the device
612
613 # Before state:
614 # ------------
615 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
616 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
617 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
618 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
619 # ip prefix-list DenyPrefix description denies lab IPv4 networks
620 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
621 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
622 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
623 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
624
625 - name: Delete all prefix-lists
626 cisco.nxos.nxos_prefix_lists:
627 state: deleted
628
629 # Task output
630 # -------------
631 # before:
632 # - afi: ipv4
633 # prefix_lists:
634 # - description: allows engineering IPv4 networks
635 # entries:
636 # - sequence: 10
637 # action: permit
638 # prefix: 192.0.2.0/23
639 # eq: 24
640 # - sequence: 20
641 # action: permit
642 # prefix: 198.51.100.128/26
643 # name: AllowPrefix
644 # - description: denies lab IPv4 networks
645 # entries:
646 # - sequence: 20
647 # action: deny
648 # prefix: 203.0.113.0/24
649 # le: 25
650 # name: DenyPrefix
651 #
652 # - afi: ipv6
653 # prefix_lists:
654 # - description: allows engineering IPv6 networks
655 # entries:
656 # - sequence: 8
657 # action: permit
658 # prefix: "2001:db8:400::/38"
659 # - sequence: 20
660 # action: permit
661 # prefix: "2001:db8:8000::/35"
662 # le: 37
663 # name: AllowIPv6Prefix
664 #
665 # commands:
666 # - "no ip prefix-list AllowPrefix"
667 # - "no ip prefix-list DenyPrefix"
668 # - "no ipv6 prefix-list AllowIPv6Prefix"
669 #
670 # after: []
671 #
672 # After state:
673 # ------------
674 # nxos-9k-rdo# show running-config | section 'ip(.*) prefix-list'
675 # nxos-9k-rdo#
676
677 # Using rendered
678
679 - name: Render platform specific configuration lines with state rendered (without connecting to the device)
680 cisco.nxos.nxos_prefix_lists: &id001
681 config:
682 - afi: ipv4
683 prefix_lists:
684 - name: AllowPrefix
685 description: allows engineering IPv4 networks
686 entries:
687 - sequence: 10
688 action: permit
689 prefix: 192.0.2.0/23
690 eq: 24
691 - sequence: 20
692 action: permit
693 prefix: 198.51.100.128/26
694 - name: DenyPrefix
695 description: denies lab IPv4 networks
696 entries:
697 - sequence: 20
698 action: deny
699 prefix: 203.0.113.0/24
700 le: 25
701
702 - afi: ipv6
703 prefix_lists:
704 - name: AllowIPv6Prefix
705 description: allows engineering IPv6 networks
706 entries:
707 - sequence: 8
708 action: permit
709 prefix: "2001:db8:400::/38"
710 - sequence: 20
711 action: permit
712 prefix: "2001:db8:8000::/35"
713 le: 37
714 state: rendered
715
716 # Task Output (redacted)
717 # -----------------------
718 # rendered:
719 # - afi: ipv4
720 # prefix_lists:
721 # - description: allows engineering IPv4 networks
722 # entries:
723 # - sequence: 10
724 # action: permit
725 # prefix: 192.0.2.0/23
726 # eq: 24
727 # - sequence: 20
728 # action: permit
729 # prefix: 198.51.100.128/26
730 # name: AllowPrefix
731 # - description: denies lab IPv4 networks
732 # entries:
733 # - sequence: 20
734 # action: deny
735 # prefix: 203.0.113.0/24
736 # le: 25
737 # name: DenyPrefix
738 #
739 # - afi: ipv6
740 # prefix_lists:
741 # - description: allows engineering IPv6 networks
742 # entries:
743 # - sequence: 8
744 # action: permit
745 # prefix: "2001:db8:400::/38"
746 # - sequence: 20
747 # action: permit
748 # prefix: "2001:db8:8000::/35"
749 # le: 37
750 # name: AllowIPv6Prefix
751
752 # Using parsed
753
754 # parsed.cfg
755 # ------------
756 # ip prefix-list AllowPrefix description allows engineering IPv4 networks
757 # ip prefix-list AllowPrefix seq 10 permit 192.0.2.0/23 eq 24
758 # ip prefix-list AllowPrefix seq 20 permit 198.51.100.128/26
759 # ip prefix-list DenyPrefix description denies lab IPv4 networks
760 # ip prefix-list DenyPrefix seq 20 deny 203.0.113.0/24 le 25
761 # ipv6 prefix-list AllowIPv6Prefix description allows engineering IPv6 networks
762 # ipv6 prefix-list AllowIPv6Prefix seq 8 permit 2001:db8:400::/38
763 # ipv6 prefix-list AllowIPv6Prefix seq 20 permit 2001:db8:8000::/35 le 37
764
765 - name: Parse externally provided prefix-lists configuration
766 register: result
767 cisco.nxos.nxos_prefix_lists:
768 running_config: "{{ lookup('file', './parsed.cfg') }}"
769 state: parsed
770
771 # Task output (redacted)
772 # -----------------------
773 # parsed:
774 # - afi: ipv4
775 # prefix_lists:
776 # - description: allows engineering IPv4 networks
777 # entries:
778 # - sequence: 10
779 # action: permit
780 # prefix: 192.0.2.0/23
781 # eq: 24
782 # - sequence: 20
783 # action: permit
784 # prefix: 198.51.100.128/26
785 # name: AllowPrefix
786 # - description: denies lab IPv4 networks
787 # entries:
788 # - sequence: 20
789 # action: deny
790 # prefix: 203.0.113.0/24
791 # le: 25
792 # name: DenyPrefix
793 #
794 # - afi: ipv6
795 # prefix_lists:
796 # - description: allows engineering IPv6 networks
797 # entries:
798 # - sequence: 8
799 # action: permit
800 # prefix: "2001:db8:400::/38"
801 # - sequence: 20
802 # action: permit
803 # prefix: "2001:db8:8000::/35"
804 # le: 37
805 # name: AllowIPv6Prefix
806 """
807
808 from ansible.module_utils.basic import AnsibleModule
809
810 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.prefix_lists.prefix_lists import (
811 Prefix_listsArgs,
812 )
813 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.prefix_lists.prefix_lists import (
814 Prefix_lists,
815 )
816
817
818 def main():
819 """
820 Main entry point for module execution
821
822 :returns: the result form module invocation
823 """
824 module = AnsibleModule(
825 argument_spec=Prefix_listsArgs.argument_spec,
826 mutually_exclusive=[["config", "running_config"]],
827 required_if=[
828 ["state", "merged", ["config"]],
829 ["state", "replaced", ["config"]],
830 ["state", "overridden", ["config"]],
831 ["state", "rendered", ["config"]],
832 ["state", "parsed", ["running_config"]],
833 ],
834 supports_check_mode=True,
835 )
836
837 result = Prefix_lists(module).execute_module()
838 module.exit_json(**result)
839
840
841 if __name__ == "__main__":
842 main()