Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 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_hsrp_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: nxos_hsrp_interfaces
18 short_description: HSRP interfaces resource module
19 description: Resource module to configure HSRP on interfaces.
20 version_added: 10.1.0
21 author:
22 - Chris Van Heuveln (@chrisvanheuveln)
23 - Sagar Paul (@KB-perByte)
24 notes:
25 - Tested against NX-OS 10.4(2) Nexus 9000v.
26 - Feature bfd and hsrp, should be enabled for this module.
27 - Unsupported for Cisco MDS
28 options:
29 running_config:
30 description:
31 - This option is used only with state I(parsed).
32 - The value of this option should be the output received from the NX-OS device
33 by executing the command B(show running-config | section '^interface').
34 - The state I(parsed) reads the configuration from C(running_config) option and
35 transforms it into Ansible structured data as per the resource module's argspec
36 and the value is then returned in the I(parsed) key within the result.
37 type: str
38 config:
39 description: A dictionary of HSRP configuration options to add to interface
40 type: list
41 elements: dict
42 suboptions:
43 name:
44 type: str
45 description: The name of the interface.
46 bfd:
47 type: str
48 description:
49 - Enable/Disable HSRP Bidirectional Forwarding Detection (BFD) on the interface.
50 - B(Deprecated), Use standby.bfd instead, the facts would always render bfd information
51 as a part of standby configuration
52 - This option has been deprecated and will be removed in a release after 2028-06-01.
53 choices:
54 - enable
55 - disable
56 standby_options:
57 description: Group number and group options for standby (HSRP)
58 type: list
59 elements: dict
60 suboptions:
61 group_no:
62 description: Group number
63 type: int
64 authentication:
65 description: Authentication configuration
66 type: dict
67 suboptions:
68 key_chain:
69 description: Set key chain
70 type: str
71 key_string:
72 description: Set key string
73 type: str
74 password_text:
75 description: Password text valid for plain text and and key-string
76 type: str
77 follow:
78 description: Groups to be followed
79 type: str
80 mac_address:
81 description: Virtual MAC address
82 type: str
83 ip:
84 description: Enable HSRP IPv4 and set the virtual IP address
85 type: list
86 elements: dict
87 suboptions:
88 virtual_ip:
89 description: Virtual IP address
90 type: str
91 secondary:
92 description: Make this IP address a secondary virtual IP address
93 type: bool
94 group_name:
95 description: Redundancy name string
96 type: str
97 preempt:
98 description: Overthrow lower priority Active routers
99 type: dict
100 suboptions:
101 minimum:
102 description: Delay at least this long
103 type: int
104 reload:
105 description: Delay after reload
106 type: int
107 sync:
108 description: Wait for IP redundancy clients
109 type: int
110 priority:
111 description: Priority level
112 type: dict
113 suboptions:
114 level:
115 description: Priority level value
116 type: int
117 default: 100
118 upper:
119 description: Set upper threshold value (forwarding-threshold)
120 type: int
121 lower:
122 description: Set lower threshold value (forwarding-threshold)
123 type: int
124 timer:
125 description: Overthrow lower priority Active routers
126 type: dict
127 suboptions:
128 hello_interval:
129 description: Hello interval in seconds
130 type: int
131 hold_time:
132 description: Hold time in seconds
133 type: int
134 msec:
135 description: Specify hello interval in milliseconds
136 type: bool
137 track:
138 description: Priority tracking
139 type: list
140 elements: dict
141 suboptions:
142 object_no:
143 description: Track object number
144 type: int
145 decrement:
146 description: Priority decrement
147 type: int
148 standby:
149 description:
150 - Standby options generic, not idempotent when version 1 (HSRP)
151 type: dict
152 suboptions:
153 bfd:
154 description: Enable HSRP BFD
155 type: bool
156 delay:
157 description: HSRP initialization delay
158 type: dict
159 suboptions:
160 minimum:
161 description: Delay at least this long
162 type: int
163 reload:
164 description: Delay after reload
165 type: int
166 mac_refresh:
167 description: Refresh MAC cache on switch by periodically sending packet from virtual mac address
168 type: int
169 use_bia:
170 description: HSRP uses interface's burned in address (does not work with mac address)
171 type: dict
172 suboptions:
173 set:
174 description: Set use-bia only
175 type: bool
176 scope:
177 description: Scope interface option (hsrp use-bia scope interface)
178 type: bool
179 version:
180 description: HSRP version
181 type: int
182 choices:
183 - 1
184 - 2
185 state:
186 choices:
187 - merged
188 - replaced
189 - overridden
190 - deleted
191 - rendered
192 - gathered
193 - parsed
194 default: merged
195 description:
196 - The state the configuration should be left in
197 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
198 on the device.
199 - The state I(rendered) will transform the configuration in C(config) option to
200 platform specific CLI commands which will be returned in the I(rendered) key
201 within the result. For state I(rendered) active connection to remote host is
202 not required.
203 - The state I(gathered) will fetch the running configuration from device and transform
204 it into structured data in the format as per the resource module argspec and
205 the value is returned in the I(gathered) key within the result.
206 - The state I(parsed) reads the configuration from C(running_config) option and
207 transforms it into JSON format as per the resource module parameters and the
208 value is returned in the I(parsed) key within the result. The value of C(running_config)
209 option should be the same format as the output of command
210 I(show running-config | section ^interface) executed on device. For state I(parsed) active
211 connection to remote host is not required.
212 type: str
213 """
214
215 EXAMPLES = """
216 # Using merged
217
218 # Before state:
219 # -------------
220 #
221 # switch# show running-config | section interface
222 # interface Vlan1
223 # interface Vlan10
224 # interface Vlan14
225 # bandwidth 99999
226 # interface Vlan1000
227 # interface Ethernet1/1
228 # interface Ethernet1/2
229 # interface Ethernet1/3
230 # interface Ethernet1/4
231 # interface Ethernet1/5
232 # interface Ethernet1/6
233 # interface Ethernet1/7
234
235 - name: Merge provided configuration with device configuration
236 cisco.nxos.nxos_hsrp_interfaces:
237 config:
238 - name: Ethernet1/1
239 standby:
240 bfd: true
241 mac_refresh: 400
242 version: 2
243 standby_options:
244 - authentication:
245 key_string: SECUREKEY10
246 group_name: VLAN10-GROUP
247 group_no: 10
248 ip:
249 - secondary: true
250 virtual_ip: 10.10.10.2
251 mac_address: 00CC.10DD.10EE
252 state: merged
253
254 # Task Output
255 # -----------
256 #
257 # before:
258 # - name: Vlan1
259 # - name: Vlan10
260 # - name: Vlan14
261 # - name: Vlan1000
262 # - name: Ethernet1/1
263 # standby:
264 # bfd: true
265 # - name: Ethernet1/2
266 # - name: Ethernet1/3
267 # - name: Ethernet1/4
268 # - name: Ethernet1/5
269 # - name: Ethernet1/6
270 # - name: Ethernet1/7
271 # commands:
272 # - interface Ethernet1/1
273 # - hsrp version 2
274 # - hsrp mac-refresh 400
275 # - hsrp 10
276 # - mac-address 00CC.10DD.10EE
277 # - name VLAN10-GROUP
278 # - authentication md5 key-string SECUREKEY10
279 # - ip 10.10.10.2 secondary
280 # - interface Ethernet1/2
281 # - hsrp bfd
282 # - hsrp version 2
283 # - hsrp mac-refresh 400
284 # - hsrp 20
285 # - mac-address 00CC.10DD.10EF
286 # - name VLAN20-GROUP
287 # - authentication md5 key-chain SECUREKEY20
288 # - ip 10.10.10.3 secondary
289 # after:
290 # - name: Vlan1
291 # - name: Vlan10
292 # - name: Vlan14
293 # - name: Vlan1000
294 # - name: Ethernet1/1
295 # standby:
296 # bfd: true
297 # mac_refresh: 400
298 # version: 2
299 # standby_options:
300 # - authentication:
301 # key_string: SECUREKEY10
302 # group_name: VLAN10-GROUP
303 # group_no: 10
304 # ip:
305 # - secondary: true
306 # virtual_ip: 10.10.10.2
307 # mac_address: 00CC.10DD.10EE
308 # - name: Ethernet1/2
309 # standby:
310 # bfd: true
311 # mac_refresh: 400
312 # version: 2
313 # standby_options:
314 # - authentication:
315 # key_chain: SECUREKEY20
316 # group_name: VLAN20-GROUP
317 # group_no: 20
318 # ip:
319 # - secondary: true
320 # virtual_ip: 10.10.10.3
321 # mac_address: 00CC.10DD.10EF
322 # - name: Ethernet1/3
323 # - name: Ethernet1/4
324 # - name: Ethernet1/5
325 # - name: Ethernet1/6
326 # - name: Ethernet1/7
327
328 # After state:
329 # ------------
330 #
331 # switch# show running-config | section interface
332 # interface Vlan1
333 # interface Vlan10
334 # interface Vlan14
335 # bandwidth 99999
336 # interface Vlan1000
337 # interface Ethernet1/1
338 # no switchport
339 # hsrp bfd
340 # hsrp version 2
341 # hsrp mac-refresh 400
342 # hsrp 10
343 # authentication md5 key-string SECUREKEY10
344 # name VLAN10-GROUP
345 # mac-address 00CC.10DD.10EE
346 # ip 10.10.10.2 secondary
347 # interface Ethernet1/2
348 # no switchport
349 # hsrp bfd
350 # hsrp version 2
351 # hsrp mac-refresh 400
352 # hsrp 20
353 # authentication md5 key-chain SECUREKEY20
354 # name VLAN20-GROUP
355 # mac-address 00CC.10DD.10EF
356 # ip 10.10.10.3 secondary
357 # interface Ethernet1/3
358 # interface Ethernet1/4
359 # interface Ethernet1/5
360 # interface Ethernet1/6
361 # interface Ethernet1/7
362
363 # Using replaced
364
365 # Before state:
366 # -------------
367 #
368 # switch# show running-config | section interface
369 # interface Vlan1
370 # interface Vlan10
371 # interface Vlan14
372 # bandwidth 99999
373 # interface Vlan1000
374 # interface Ethernet1/1
375 # no switchport
376 # hsrp bfd
377 # hsrp version 2
378 # hsrp mac-refresh 400
379 # hsrp 10
380 # authentication md5 key-string SECUREKEY10
381 # name VLAN10-GROUP
382 # mac-address 00CC.10DD.10EE
383 # ip 10.10.10.2 secondary
384 # interface Ethernet1/2
385 # no switchport
386 # hsrp bfd
387 # hsrp version 2
388 # hsrp mac-refresh 400
389 # hsrp 20
390 # authentication md5 key-chain SECUREKEY20
391 # name VLAN20-GROUP
392 # mac-address 00CC.10DD.10EF
393 # ip 10.10.10.3 secondary
394 # interface Ethernet1/3
395 # interface Ethernet1/4
396 # interface Ethernet1/5
397 # interface Ethernet1/6
398 # interface Ethernet1/7
399
400 - name: Replaces device configuration of listed interfaces with provided configuration
401 cisco.nxos.nxos_hsrp_interfaces:
402 config:
403 - name: Ethernet1/1
404 standby:
405 bfd: true
406 mac_refresh: 400
407 version: 2
408 standby_options:
409 - authentication:
410 key_string: SECUREKEY10
411 group_name: VLAN11-GROUP
412 group_no: 11
413 mac_address: 00CC.10DD.10EE
414 - name: Ethernet1/2
415 standby:
416 bfd: true
417 mac_refresh: 400
418 version: 2
419 standby_options:
420 - authentication:
421 key_chain: SECUREKEY20
422 group_name: VLAN20-GROUP
423 group_no: 20
424 mac_address: 00CC.10DD.10EF
425 state: replaced
426
427 # Task Output
428 # -----------
429 #
430 # before:
431 # - name: Vlan1
432 # - name: Vlan10
433 # - name: Vlan14
434 # - name: Vlan1000
435 # - name: Ethernet1/1
436 # standby:
437 # bfd: true
438 # mac_refresh: 400
439 # version: 2
440 # standby_options:
441 # - authentication:
442 # key_string: SECUREKEY10
443 # group_name: VLAN10-GROUP
444 # group_no: 10
445 # ip:
446 # - secondary: true
447 # virtual_ip: 10.10.10.2
448 # mac_address: 00CC.10DD.10EE
449 # - name: Ethernet1/2
450 # standby:
451 # bfd: true
452 # mac_refresh: 400
453 # version: 2
454 # standby_options:
455 # - authentication:
456 # key_chain: SECUREKEY20
457 # group_name: VLAN20-GROUP
458 # group_no: 20
459 # ip:
460 # - secondary: true
461 # virtual_ip: 10.10.10.3
462 # mac_address: 00CC.10DD.10EF
463 # - name: Ethernet1/3
464 # - name: Ethernet1/4
465 # - name: Ethernet1/5
466 # - name: Ethernet1/6
467 # - name: Ethernet1/7
468 # commands:
469 # - interface Ethernet1/1
470 # - hsrp 11
471 # - mac-address 00CC.10DD.10EE
472 # - name VLAN11-GROUP
473 # - authentication md5 key-string SECUREKEY10
474 # - no hsrp 10
475 # - interface Ethernet1/2
476 # - hsrp 20
477 # - no ip 10.10.10.3 secondary
478 # after:
479 # - name: Vlan1
480 # - name: Vlan10
481 # - name: Vlan14
482 # - name: Vlan1000
483 # - name: Ethernet1/1
484 # standby:
485 # bfd: true
486 # mac_refresh: 400
487 # version: 2
488 # standby_options:
489 # - authentication:
490 # key_string: SECUREKEY10
491 # group_name: VLAN11-GROUP
492 # group_no: 11
493 # mac_address: 00CC.10DD.10EE
494 # - name: Ethernet1/2
495 # standby:
496 # bfd: true
497 # mac_refresh: 400
498 # version: 2
499 # standby_options:
500 # - authentication:
501 # key_chain: SECUREKEY20
502 # group_name: VLAN20-GROUP
503 # group_no: 20
504 # mac_address: 00CC.10DD.10EF
505 # - name: Ethernet1/3
506 # - name: Ethernet1/4
507 # - name: Ethernet1/5
508 # - name: Ethernet1/6
509 # - name: Ethernet1/7
510
511
512 # After state:
513 # ------------
514 #
515 # switch# show running-config | section interface
516 # interface Vlan1
517 # interface Vlan10
518 # interface Vlan14
519 # bandwidth 99999
520 # interface Vlan1000
521 # interface Ethernet1/1
522 # no switchport
523 # hsrp bfd
524 # hsrp version 2
525 # hsrp mac-refresh 400
526 # hsrp 11
527 # authentication md5 key-string SECUREKEY10
528 # name VLAN11-GROUP
529 # mac-address 00CC.10DD.10EE
530 # interface Ethernet1/2
531 # no switchport
532 # hsrp bfd
533 # hsrp version 2
534 # hsrp mac-refresh 400
535 # hsrp 20
536 # authentication md5 key-chain SECUREKEY20
537 # name VLAN20-GROUP
538 # mac-address 00CC.10DD.10EF
539 # interface Ethernet1/3
540 # interface Ethernet1/4
541 # interface Ethernet1/5
542 # interface Ethernet1/6
543 # interface Ethernet1/7
544
545 # Using overridden
546
547 # Before state:
548 # -------------
549 #
550 # switch# show running-config | section interface
551 # interface Vlan1
552 # interface Vlan10
553 # interface Vlan14
554 # bandwidth 99999
555 # interface Vlan1000
556 # interface Ethernet1/1
557 # no switchport
558 # hsrp bfd
559 # hsrp version 2
560 # hsrp mac-refresh 400
561 # hsrp 10
562 # authentication md5 key-string SECUREKEY10
563 # name VLAN10-GROUP
564 # mac-address 00CC.10DD.10EE
565 # ip 10.10.10.2 secondary
566 # interface Ethernet1/2
567 # no switchport
568 # hsrp bfd
569 # hsrp version 2
570 # hsrp mac-refresh 400
571 # hsrp 20
572 # authentication md5 key-chain SECUREKEY20
573 # name VLAN20-GROUP
574 # mac-address 00CC.10DD.10EF
575 # ip 10.10.10.3 secondary
576
577 - name: Override device configuration of all interfaces with provided configuration
578 cisco.nxos.nxos_hsrp_interfaces:
579 config:
580 - name: Ethernet1/1
581 standby:
582 bfd: true
583 mac_refresh: 400
584 version: 2
585 standby_options:
586 - authentication:
587 key_string: SECUREKEY10
588 group_name: VLAN11-GROUP
589 group_no: 11
590 mac_address: 00CC.10DD.10EE
591 - name: Ethernet1/2
592 standby:
593 bfd: true
594 mac_refresh: 400
595 version: 2
596 standby_options:
597 - authentication:
598 key_chain: SECUREKEY20
599 group_name: VLAN20-GROUP
600 group_no: 20
601 mac_address: 00CC.10DD.10EF
602 state: overridden
603
604 # Task Output
605 # -----------
606 #
607 # before:
608 # - name: Vlan1
609 # - name: Vlan10
610 # - name: Vlan14
611 # - name: Vlan1000
612 # - name: Ethernet1/1
613 # standby:
614 # bfd: true
615 # mac_refresh: 400
616 # version: 2
617 # standby_options:
618 # - authentication:
619 # key_string: SECUREKEY10
620 # group_name: VLAN10-GROUP
621 # group_no: 10
622 # ip:
623 # - secondary: true
624 # virtual_ip: 10.10.10.2
625 # mac_address: 00CC.10DD.10EE
626 # - name: Ethernet1/2
627 # standby:
628 # bfd: true
629 # mac_refresh: 400
630 # version: 2
631 # standby_options:
632 # - authentication:
633 # key_chain: SECUREKEY20
634 # group_name: VLAN20-GROUP
635 # group_no: 20
636 # ip:
637 # - secondary: true
638 # virtual_ip: 10.10.10.3
639 # mac_address: 00CC.10DD.10EF
640 # - name: Ethernet1/3
641 # - name: Ethernet1/4
642 # - name: Ethernet1/5
643 # - name: Ethernet1/6
644 # - name: Ethernet1/7
645 # commands:
646 # - interface Ethernet1/1
647 # - hsrp 11
648 # - mac-address 00CC.10DD.10EE
649 # - name VLAN11-GROUP
650 # - authentication md5 key-string SECUREKEY10
651 # - no hsrp 10
652 # - interface Ethernet1/2
653 # - hsrp 20
654 # - no ip 10.10.10.3 secondary
655 # after:
656 # - name: Vlan1
657 # - name: Vlan10
658 # - name: Vlan14
659 # - name: Vlan1000
660 # - name: Ethernet1/1
661 # standby:
662 # bfd: true
663 # mac_refresh: 400
664 # version: 2
665 # standby_options:
666 # - authentication:
667 # key_string: SECUREKEY10
668 # group_name: VLAN11-GROUP
669 # group_no: 11
670 # mac_address: 00CC.10DD.10EE
671 # - name: Ethernet1/2
672 # standby:
673 # bfd: true
674 # mac_refresh: 400
675 # version: 2
676 # standby_options:
677 # - authentication:
678 # key_chain: SECUREKEY20
679 # group_name: VLAN20-GROUP
680 # group_no: 20
681 # mac_address: 00CC.10DD.10EF
682 # - name: Ethernet1/3
683 # - name: Ethernet1/4
684 # - name: Ethernet1/5
685 # - name: Ethernet1/6
686 # - name: Ethernet1/7
687
688 # After state:
689 # ------------
690 #
691 # switch# show running-config | section interface
692 # interface Vlan1
693 # interface Vlan10
694 # interface Vlan14
695 # bandwidth 99999
696 # interface Vlan1000
697 # interface Ethernet1/1
698 # no switchport
699 # hsrp bfd
700 # hsrp version 2
701 # hsrp mac-refresh 400
702 # hsrp 11
703 # authentication md5 key-string SECUREKEY10
704 # name VLAN11-GROUP
705 # mac-address 00CC.10DD.10EE
706 # interface Ethernet1/2
707 # no switchport
708 # hsrp bfd
709 # hsrp version 2
710 # hsrp mac-refresh 400
711 # hsrp 20
712 # authentication md5 key-chain SECUREKEY20
713 # name VLAN20-GROUP
714 # mac-address 00CC.10DD.10EF
715 # interface Ethernet1/3
716 # interface Ethernet1/4
717 # interface Ethernet1/5
718 # interface Ethernet1/6
719 # interface Ethernet1/7
720
721
722 # Using deleted
723
724 # Before state:
725 # -------------
726 #
727 # switch# show running-config | section interface
728 # interface Vlan1
729 # interface Vlan10
730 # interface Vlan14
731 # bandwidth 99999
732 # interface Vlan1000
733 # interface Ethernet1/1
734 # no switchport
735 # hsrp bfd
736 # hsrp version 2
737 # hsrp mac-refresh 400
738 # hsrp 10
739 # authentication md5 key-string SECUREKEY10
740 # name VLAN10-GROUP
741 # mac-address 00CC.10DD.10EE
742 # ip 10.10.10.2 secondary
743 # interface Ethernet1/2
744 # no switchport
745 # hsrp bfd
746 # hsrp version 2
747 # hsrp mac-refresh 400
748 # hsrp 20
749 # authentication md5 key-chain SECUREKEY20
750 # name VLAN20-GROUP
751 # mac-address 00CC.10DD.10EF
752 # ip 10.10.10.3 secondary
753 # interface Ethernet1/3
754 # interface Ethernet1/4
755 # interface Ethernet1/5
756 # interface Ethernet1/6
757 # interface Ethernet1/7
758
759 - name: Delete or return interface parameters to default settings
760 cisco.nxos.nxos_hsrp_interfaces:
761 config:
762 - name: Ethernet1/1
763 standby:
764 bfd: true
765 mac_refresh: 400
766 version: 2
767 standby_options:
768 - authentication:
769 key_string: SECUREKEY10
770 group_name: VLAN11-GROUP
771 group_no: 11
772 mac_address: 00CC.10DD.10EE
773 - name: Ethernet1/2
774 standby:
775 bfd: true
776 mac_refresh: 400
777 version: 2
778 standby_options:
779 - authentication:
780 key_chain: SECUREKEY20
781 group_name: VLAN20-GROUP
782 group_no: 20
783 mac_address: 00CC.10DD.10EF
784 state: deleted
785
786 # Task Output
787 # -----------
788 #
789 # before:
790 # - name: Vlan1
791 # - name: Vlan10
792 # - name: Vlan14
793 # - name: Vlan1000
794 # - name: Ethernet1/1
795 # standby:
796 # bfd: true
797 # mac_refresh: 400
798 # version: 2
799 # standby_options:
800 # - authentication:
801 # key_string: SECUREKEY10
802 # group_name: VLAN10-GROUP
803 # group_no: 10
804 # ip:
805 # - secondary: true
806 # virtual_ip: 10.10.10.2
807 # mac_address: 00CC.10DD.10EE
808 # - name: Ethernet1/2
809 # standby:
810 # bfd: true
811 # mac_refresh: 400
812 # version: 2
813 # standby_options:
814 # - authentication:
815 # key_chain: SECUREKEY20
816 # group_name: VLAN20-GROUP
817 # group_no: 20
818 # ip:
819 # - secondary: true
820 # virtual_ip: 10.10.10.3
821 # mac_address: 00CC.10DD.10EF
822 # - name: Ethernet1/3
823 # - name: Ethernet1/4
824 # - name: Ethernet1/5
825 # - name: Ethernet1/6
826 # - name: Ethernet1/7
827 # commands:
828 # - interface Ethernet1/1
829 # - no hsrp bfd
830 # - no hsrp version 2
831 # - no hsrp mac-refresh 400
832 # - no hsrp 10
833 # - interface Ethernet1/2
834 # - no hsrp bfd
835 # - no hsrp version 2
836 # - no hsrp mac-refresh 400
837 # - no hsrp 20
838 # after:
839 # - name: Vlan1
840 # - name: Vlan10
841 # - name: Vlan14
842 # - name: Vlan1000
843 # - name: Ethernet1/1
844 # - name: Ethernet1/2
845 # - name: Ethernet1/3
846 # - name: Ethernet1/4
847 # - name: Ethernet1/5
848 # - name: Ethernet1/6
849
850 # After state:
851 # ------------
852 #
853 # switch# show running-config | section interface
854 # interface Vlan1
855 # interface Vlan10
856 # interface Vlan14
857 # bandwidth 99999
858 # interface Vlan1000
859 # interface Ethernet1/1
860 # no switchport
861 # interface Ethernet1/2
862 # no switchport
863 # interface Ethernet1/3
864 # interface Ethernet1/4
865 # interface Ethernet1/5
866 # interface Ethernet1/6
867 # interface Ethernet1/7
868
869 # Using rendered
870
871 - name: Use rendered state to convert task input to device specific commands
872 cisco.nxos.nxos_hsrp_interfaces:
873 config:
874 - name: Ethernet1/1
875 description: outbound-intf
876 mode: layer3
877 speed: 100
878 - name: Ethernet1/2
879 mode: layer2
880 enabled: true
881 duplex: full
882 state: rendered
883
884 # Task Output
885 # -----------
886 #
887 # rendered:
888 # - interface Vlan1
889 # - hsrp version 2
890 # - hsrp 10
891 # - timers msec 250 255
892 # - authentication md5 key-chain test
893 # - interface Vlan10
894 # - hsrp bfd
895 # - hsrp version 2
896 # - hsrp mac-refresh 400
897 # - hsrp 10
898 # - mac-address 00CC.10DD.10EE
899 # - name VLAN10-GROUP
900 # - preempt delay minimum 15 reload 120 sync 10
901 # - authentication md5 key-string SECUREKEY10
902 # - ip 10.10.10.2 secondary
903 # - interface Vlan14
904 # - hsrp bfd
905 # - hsrp version 2
906 # - hsrp delay 22 123
907 # - hsrp mac-refresh 300
908 # - hsrp 14
909 # - follow VLAN14-GROUP
910 # - mac-address 00AA.14BB.14CC
911 # - ip 192.168.14.1 secondary
912 # - ip 192.168.14.2 secondary
913 # - hsrp 15
914 # - mac-address 00BB.14CC.15DD
915 # - preempt delay minimum 10 reload 100 sync 5
916 # - priority 22 forwarding-threshold lower 12 upper 22
917 # - timers msec 456 33
918 # - authentication md5 key-string SECUREKEY14
919 # - interface Vlan1000
920 # - hsrp 10
921 # - mac-address 0423.4567.89AB
922 # - name testhsr
923 # - preempt delay minimum 33 reload 23 sync 22
924 # - priority 22 forwarding-threshold lower 12 upper 22
925 # - timers msec 456 33
926 # - authentication md5 key-string testmesecurte
927 # - ip 10.15.8.1 secondary
928
929
930 # Using parsed
931
932 # parsed.cfg
933 # ------------
934 #
935 # interface Vlan1
936 # hsrp version 2
937 # hsrp 10
938 # authentication md5 key-chain test
939 # timers msec 250 255
940 # interface Vlan10
941 # hsrp bfd
942 # hsrp version 2
943 # hsrp mac-refresh 400
944 # hsrp 10
945 # authentication md5 key-string SECUREKEY10
946 # name VLAN10-GROUP
947 # mac-address 00CC.10DD.10EE
948 # preempt delay minimum 15 reload 120 sync 10
949 # ip 10.10.10.2 secondary
950 # interface Vlan14
951 # bandwidth 99999
952 # hsrp bfd
953 # hsrp version 2
954 # hsrp delay minimum 22 reload 123
955 # hsrp mac-refresh 300
956 # hsrp 14
957 # follow VLAN14-GROUP
958 # mac-address 00AA.14BB.14CC
959 # ip 192.168.14.1 secondary
960 # ip 192.168.14.2 secondary
961 # hsrp 15
962 # authentication md5 key-string SECUREKEY14
963 # mac-address 00BB.14CC.15DD
964 # preempt delay minimum 10 reload 100 sync 5
965 # priority 22 forwarding-threshold lower 12 upper 22
966 # timers msec 456 33
967 # interface Vlan1000
968 # hsrp 10
969 # authentication md5 key-string testmesecurte
970 # name testhsr
971 # mac-address 0423.4567.89AB
972 # preempt delay minimum 33 reload 23 sync 22
973 # priority 22 forwarding-threshold lower 12 upper 22
974 # timers msec 456 33
975 # ip 10.15.8.1 secondary
976
977 - name: Use parsed state to convert externally supplied config to structured format
978 cisco.nxos.nxos_hsrp_interfaces:
979 running_config: "{{ lookup('file', 'parsed.cfg') }}"
980 state: parsed
981
982 # Task output
983 # -----------
984 #
985 # {"parsed": [
986 # {
987 # "name": "Vlan1",
988 # "standby": {
989 # "version": 2
990 # },
991 # "standby_options": [
992 # {
993 # "authentication": {
994 # "key_chain": "test"
995 # },
996 # "group_no": 10,
997 # "timer": {
998 # "hello_interval": 250,
999 # "hold_time": 255,
1000 # "msec": true
1001 # }
1002 # }
1003 # ]
1004 # },
1005 # {
1006 # "name": "Vlan10",
1007 # "standby": {
1008 # "bfd": true,
1009 # "mac_refresh": 400,
1010 # "version": 2
1011 # },
1012 # "standby_options": [
1013 # {
1014 # "authentication": {
1015 # "key_string": "SECUREKEY10"
1016 # },
1017 # "group_name": "VLAN10-GROUP",
1018 # "group_no": 10,
1019 # "ip": [
1020 # {
1021 # "secondary": true,
1022 # "virtual_ip": "10.10.10.2"
1023 # }
1024 # ],
1025 # "mac_address": "00CC.10DD.10EE",
1026 # "preempt": {
1027 # "minimum": 15,
1028 # "reload": 120,
1029 # "sync": 10
1030 # }
1031 # }
1032 # ]
1033 # },
1034 # {
1035 # "name": "Vlan14",
1036 # "standby": {
1037 # "bfd": true,
1038 # "delay": {
1039 # "minimum": 22,
1040 # "reload": 123
1041 # },
1042 # "mac_refresh": 300,
1043 # "version": 2
1044 # },
1045 # "standby_options": [
1046 # {
1047 # "follow": "VLAN14-GROUP",
1048 # "group_no": 14,
1049 # "ip": [
1050 # {
1051 # "secondary": true,
1052 # "virtual_ip": "192.168.14.1"
1053 # },
1054 # {
1055 # "secondary": true,
1056 # "virtual_ip": "192.168.14.2"
1057 # }
1058 # ],
1059 # "mac_address": "00AA.14BB.14CC"
1060 # },
1061 # {
1062 # "authentication": {
1063 # "key_string": "SECUREKEY14"
1064 # },
1065 # "group_no": 15,
1066 # "mac_address": "00BB.14CC.15DD",
1067 # "preempt": {
1068 # "minimum": 10,
1069 # "reload": 100,
1070 # "sync": 5
1071 # },
1072 # "priority": {
1073 # "level": 22,
1074 # "lower": 12,
1075 # "upper": 22
1076 # },
1077 # "timer": {
1078 # "hello_interval": 456,
1079 # "hold_time": 33,
1080 # "msec": true
1081 # }
1082 # }
1083 # ]
1084 # },
1085 # {
1086 # "name": "Vlan1000",
1087 # "standby_options": [
1088 # {
1089 # "authentication": {
1090 # "key_string": "testmesecurte"
1091 # },
1092 # "group_name": "testhsr",
1093 # "group_no": 10,
1094 # "ip": [
1095 # {
1096 # "secondary": true,
1097 # "virtual_ip": "10.15.8.1"
1098 # }
1099 # ],
1100 # "mac_address": "0423.4567.89AB",
1101 # "preempt": {
1102 # "minimum": 33,
1103 # "reload": 23,
1104 # "sync": 22
1105 # },
1106 # "priority": {
1107 # "level": 22,
1108 # "lower": 12,
1109 # "upper": 22
1110 # },
1111 # "timer": {
1112 # "hello_interval": 456,
1113 # "hold_time": 33,
1114 # "msec": true
1115 # }
1116 # }
1117 # ]}
1118 """
1119
1120 RETURN = """
1121 before:
1122 description: The configuration prior to the module execution.
1123 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1124 type: dict
1125 sample: >
1126 This output will always be in the same format as the
1127 module argspec.
1128 after:
1129 description: The resulting configuration after module execution.
1130 returned: when changed
1131 type: dict
1132 sample: >
1133 This output will always be in the same format as the
1134 module argspec.
1135 commands:
1136 description: The set of commands pushed to the remote device.
1137 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1138 type: list
1139 sample:
1140 - hsrp 14
1141 - follow VLAN14-GROUP
1142 - mac-address 00AA.14BB.14CC
1143 rendered:
1144 description: The provided configuration in the task rendered in device-native format (offline).
1145 returned: when I(state) is C(rendered)
1146 type: list
1147 sample:
1148 - hsrp 14
1149 - follow VLAN14-GROUP
1150 - mac-address 00AA.14BB.14CC
1151 gathered:
1152 description: Facts about the network resource gathered from the remote device as structured data.
1153 returned: when I(state) is C(gathered)
1154 type: list
1155 sample: >
1156 This output will always be in the same format as the
1157 module argspec.
1158 parsed:
1159 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
1160 returned: when I(state) is C(parsed)
1161 type: list
1162 sample: >
1163 This output will always be in the same format as the
1164 module argspec.
1165 """
1166
1167 from ansible.module_utils.basic import AnsibleModule
1168
1169 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.argspec.hsrp_interfaces.hsrp_interfaces import (
1170 Hsrp_interfacesArgs,
1171 )
1172 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.config.hsrp_interfaces.hsrp_interfaces import (
1173 Hsrp_interfaces,
1174 )
1175
1176
1177 def main():
1178 """
1179 Main entry point for module execution
1180
1181 :returns: the result form module invocation
1182 """
1183 module = AnsibleModule(
1184 argument_spec=Hsrp_interfacesArgs.argument_spec,
1185 mutually_exclusive=[["config", "running_config"]],
1186 required_if=[
1187 ["state", "merged", ["config"]],
1188 ["state", "replaced", ["config"]],
1189 ["state", "overridden", ["config"]],
1190 ["state", "rendered", ["config"]],
1191 ["state", "parsed", ["running_config"]],
1192 ],
1193 supports_check_mode=True,
1194 )
1195
1196 result = Hsrp_interfaces(module).execute_module()
1197 module.exit_json(**result)
1198
1199
1200 if __name__ == "__main__":
1201 main()