Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_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 ios_hsrp_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_hsrp_interfaces
18 short_description: Resource module to configure HSRP on interfaces.
19 description:
20 - >-
21 This module provides declarative management of HSRP configuration on
22 interface for Cisco IOS devices.
23 version_added: 10.1.0
24 author:
25 - Sagar Paul (@KB-perByte)
26 - Nikhil Bhasin (@nickbhasin)
27 notes:
28 - Tested against Cisco IOSXE Version 17.16.
29 - >-
30 This module works with connection C(network_cli). See
31 U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
32 - >-
33 The module examples uses callback plugin (callback_result_format=yaml) to
34 generate task output in yaml format.
35 - >-
36 For idempotency, the module consieders that version defaults to 1 as it is implied
37 by the applaince and not available in the running-config.
38 Priority defaults to 100 if not specified in the configuration.
39 options:
40 config:
41 description: A list of HSP configuration options to add to interface
42 type: list
43 elements: dict
44 suboptions:
45 name:
46 description:
47 - >-
48 Full name of the interface excluding any logical unit number, i.e.
49 GigabitEthernet0/1.
50 type: str
51 required: true
52 bfd:
53 description: Enable HSRP BFD
54 type: bool
55 delay:
56 description: HSRP initialization delay
57 type: dict
58 suboptions:
59 minimum:
60 description: Delay at least this long
61 type: int
62 reload:
63 description: Delay after reload
64 type: int
65 redirect:
66 description: Redirect configuration
67 type: dict
68 suboptions:
69 advertisement:
70 description: >-
71 Redirect advertisement messages (standby redirect advertisement
72 authentication md5)
73 type: dict
74 suboptions:
75 authentication:
76 description: Authentication configuration
77 type: dict
78 suboptions:
79 key_chain:
80 description: Set key chain
81 type: str
82 key_string:
83 description: Set key string
84 type: str
85 encryption:
86 description: Set encryption 0 (unencrypted/default) or 7 (hidden)
87 type: str
88 time_out:
89 description: Set timeout
90 type: int
91 password_text:
92 description: Password text valid for plain text and and key-string
93 type: str
94 timers:
95 description: Adjust redirect timers
96 type: dict
97 suboptions:
98 adv_timer:
99 description: Passive router advertisement interval in seconds
100 type: int
101 holddown_timer:
102 description: Passive router holddown interval in seconds
103 type: int
104 mac_refresh:
105 description: >-
106 Refresh MAC cache on switch by periodically sending packet from
107 virtual mac address
108 type: int
109 use_bia:
110 description: >-
111 HSRP uses interface's burned in address (does not work with mac
112 address)
113 type: dict
114 suboptions:
115 scope:
116 description: >-
117 Use-bia applies to all groups on this interface or
118 sub-interface
119 type: bool
120 set:
121 description: Set use-bia
122 type: bool
123 version:
124 description: HSRP version (Defaults to 1 when standby_options is present)
125 type: int
126 choices:
127 - 1
128 - 2
129 standby_options:
130 description: Group number and group options for standby (HSRP)
131 type: list
132 elements: dict
133 aliases:
134 - standby_groups
135 suboptions:
136 group_no:
137 description: Group number
138 type: int
139 follow:
140 description: Enable HSRP BFD
141 type: str
142 ip:
143 description: Enable HSRP IPv4 and set the virtual IP address
144 type: list
145 elements: dict
146 suboptions:
147 virtual_ip:
148 description: Virtual IP address
149 type: str
150 secondary:
151 description: Make this IP address a secondary virtual IP address
152 type: bool
153 ipv6:
154 description: Enable HSRP IPv6 and set the IP address
155 type: dict
156 suboptions:
157 autoconfig:
158 description: Obtain address using autoconfiguration
159 type: bool
160 addresses:
161 description: IPv6 link-local address or IPv6 prefix
162 type: list
163 elements: str
164 mac_address:
165 description: Virtual MAC address
166 type: str
167 group_name:
168 description: Redundancy name string
169 type: str
170 authentication:
171 description: Authentication configuration
172 type: dict
173 suboptions:
174 key_chain:
175 description: Set key chain
176 type: str
177 key_string:
178 description: Set key string
179 type: str
180 encryption:
181 description: Set encryption 0 (unencrypted/default) or 7 (hidden)
182 type: int
183 time_out:
184 description: Set timeout
185 type: int
186 password_text:
187 description: Password text valid for plain text and and key-string
188 type: str
189 preempt:
190 description: Overthrow lower priority Active routers
191 type: dict
192 suboptions:
193 enabled:
194 description: Enables preempt, drives the lone `standby <grp_no> preempt` command
195 type: bool
196 minimum:
197 description: Delay at least this long
198 type: int
199 reload:
200 description: Delay after reload
201 type: int
202 sync:
203 description: Wait for IP redundancy clients
204 type: int
205 delay:
206 description: Wait before preempting
207 type: bool
208 priority:
209 description: Priority level (defaults to 100)
210 type: int
211 default: 100
212 timers:
213 description: Overthrow lower priority Active routers
214 type: dict
215 suboptions:
216 hello_interval:
217 description: Hello interval in seconds
218 type: int
219 hold_time:
220 description: Hold time in seconds
221 type: int
222 msec:
223 description: Specify hello interval in milliseconds
224 type: dict
225 suboptions:
226 hello_interval:
227 description: <15-999> Hello interval in milliseconds
228 type: int
229 hold_time:
230 description: <60-3000> Hold time in milliseconds
231 type: int
232 track:
233 description: Priority tracking
234 type: list
235 elements: dict
236 suboptions:
237 track_no:
238 description: Track object number
239 type: int
240 decrement:
241 description: Priority decrement
242 type: int
243 shutdown:
244 description: Shutdown Group
245 type: bool
246 running_config:
247 description:
248 - This option is used only with state I(parsed).
249 - >-
250 The value of this option should be the output received from the IOS
251 device by executing the command B(show running-config | section
252 ^interface).
253 - >-
254 The state I(parsed) reads the configuration from C(running_config)
255 option and transforms it into Ansible structured data as per the
256 resource module's argspec and the value is then returned in the
257 I(parsed) key within the result.
258 type: str
259 state:
260 choices:
261 - merged
262 - replaced
263 - overridden
264 - deleted
265 - rendered
266 - gathered
267 - parsed
268 default: merged
269 description:
270 - The state the configuration should be left in
271 - >-
272 The states I(rendered), I(gathered) and I(parsed) does not perform any
273 change on the device.
274 - >-
275 The state I(rendered) will transform the configuration in C(config)
276 option to platform specific CLI commands which will be returned in the
277 I(rendered) key within the result. For state I(rendered) active
278 connection to remote host is not required.
279 - >-
280 The state I(gathered) will fetch the running configuration from device
281 and transform it into structured data in the format as per the resource
282 module argspec and the value is returned in the I(gathered) key within
283 the result.
284 - >-
285 The state I(parsed) reads the configuration from C(running_config)
286 option and transforms it into JSON format as per the resource module
287 parameters and the value is returned in the I(parsed) key within the
288 result. The value of C(running_config) option should be the same format
289 as the output of command I(show running-config | section ^interface)
290 executed on device. For state I(parsed) active connection to remote host
291 is not required.
292 type: str
293 """
294
295 EXAMPLES = """
296 # Using merged
297
298 # Before state:
299 # -------------
300 #
301 # Router#show running-config | section ^interface
302 # interface GigabitEthernet1
303 # description Management interface do not change
304 # ip address dhcp
305 # negotiation auto
306 # interface GigabitEthernet2
307 # no ip address
308 # speed 1000
309 # no negotiation auto
310 # interface GigabitEthernet3
311 # no ip address
312 # speed 1000
313 # no negotiation auto
314 # interface GigabitEthernet4
315 # no ip address
316
317
318 - name: Populate the device with HSRP interface configuration
319 cisco.ios.hsrp_interfaces:
320 state: merged
321 config:
322 - delay:
323 minimum: 5555
324 reload: 556
325 mac_refresh: 45
326 name: Vlan70
327 redirect:
328 advertisement:
329 authentication:
330 key_chain: HSRP_CHAIN
331 timers:
332 adv_timer: 10
333 holddown_timer: 55
334 standby_options:
335 - authentication:
336 encryption: 7
337 key_string: 0123456789ABCDEF
338 follow: MASTER_GROUP
339 group_name: PRIMARY_GROUP
340 group_no: 10
341 ip:
342 - secondary: true
343 virtual_ip: 10.0.10.2
344 preempt:
345 delay: true
346 enabled: true
347 minimum: 100
348 reload: 50
349 sync: 30
350 priority: 110
351 timers:
352 hold_time: 250
353 msec:
354 hello_interval: 200
355 track:
356 - decrement: 20
357 track_no: 1
358 - follow: MASTER_GROUP
359 group_name: IPV6_GROUP
360 group_no: 20
361 ipv6:
362 addresses:
363 - '2001:db8:20::1/64'
364 autoconfig: true
365 mac_address: 0000.0000.0014
366 priority: 120
367 version: 2
368 - delay:
369 minimum: 100
370 reload: 200
371 name: Vlan100
372 standby_options:
373 - authentication:
374 password_text: hello_secret
375 group_name: BACKUP_GROUP
376 group_no: 5
377 ip:
378 - virtual_ip: 192.168.1.1
379 preempt:
380 enabled: true
381 priority: 150
382 timers:
383 hello_interval: 5
384 hold_time: 15
385 track:
386 - decrement: 30
387 track_no: 10
388 version: 2
389 - name: GigabitEthernet3
390 standby_options:
391 - group_no: 1
392 ip:
393 - virtual_ip: 172.16.1.1
394 priority: 100
395 version: 1
396 - name: GigabitEthernet2
397 standby_options:
398 - authentication:
399 key_chain: AUTH_CHAIN
400 group_no: 2
401 ip:
402 - secondary: true
403 virtual_ip: 172.16.2.1
404 priority: 100
405 version: 1
406
407
408 # Task Output
409 # -----------
410 #
411 # before:
412 # - name: GigabitEthernet1
413 # - name: GigabitEthernet2
414 # - name: GigabitEthernet3
415 # - name: GigabitEthernet4
416 # - name: Vlan70
417 # - name: Vlan100
418 # commands:
419 # - interface Vlan70
420 # - standby version 2
421 # - standby delay minimum 5555 reload 556
422 # - standby mac-refresh 45
423 # - standby redirect timers 10 55
424 # - standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
425 # - standby 10 follow MASTER_GROUP
426 # - standby 10 name PRIMARY_GROUP
427 # - standby 10 preempt delay minimum 100 reload 50 sync 30
428 # - standby 10 priority 110
429 # - standby 10 authentication md5 key-string 7 0123456789ABCDEF
430 # - standby 10 ip 10.0.10.2 secondary
431 # - standby 10 track 1 decrement 20
432 # - standby 20 follow MASTER_GROUP
433 # - standby 20 mac-address 0000.0000.0014
434 # - standby 20 name IPV6_GROUP
435 # - standby 20 priority 120
436 # - standby 20 ipv6 autoconfig
437 # - standby 20 ipv6 2001:db8:20::1/64
438 # - interface Vlan100
439 # - standby version 2
440 # - standby delay minimum 100 reload 200
441 # - standby 5 name BACKUP_GROUP
442 # - standby 5 preempt
443 # - standby 5 priority 150
444 # - standby 5 authentication ********
445 # - standby 5 ip 192.168.1.1
446 # - standby 5 track 10 decrement 30
447 # - interface GigabitEthernet3
448 # - standby version 1
449 # - standby 1 priority 100
450 # - standby 1 ip 172.16.1.1
451 # - interface GigabitEthernet2
452 # - standby version 1
453 # - standby 2 priority 100
454 # - standby 2 authentication md5 key-chain AUTH_CHAIN
455 # - standby 2 ip 172.16.2.1 secondary
456 # after:
457 # - name: GigabitEthernet1
458 # - name: GigabitEthernet2
459 # standby_options:
460 # - authentication:
461 # key_chain: AUTH_CHAIN
462 # group_no: 2
463 # ip:
464 # - secondary: true
465 # virtual_ip: 172.16.2.1
466 # priority: 100
467 # - name: GigabitEthernet3
468 # standby_options:
469 # - group_no: 1
470 # ip:
471 # - virtual_ip: 172.16.1.1
472 # priority: 100
473 # - name: GigabitEthernet4
474 # - delay:
475 # minimum: 5555
476 # reload: 556
477 # mac_refresh: 45
478 # name: Vlan70
479 # redirect:
480 # advertisement:
481 # authentication:
482 # key_chain: HSRP_CHAIN
483 # timers:
484 # adv_timer: 10
485 # holddown_timer: 55
486 # standby_options:
487 # - authentication:
488 # encryption: 7
489 # key_string: 0123456789ABCDEF
490 # follow: MASTER_GROUP
491 # group_name: PRIMARY_GROUP
492 # group_no: 10
493 # ip:
494 # - secondary: true
495 # virtual_ip: 10.0.10.2
496 # preempt:
497 # delay: true
498 # enabled: true
499 # minimum: 100
500 # reload: 50
501 # sync: 30
502 # priority: 110
503 # track:
504 # - decrement: 20
505 # track_no: 1
506 # - follow: MASTER_GROUP
507 # group_name: IPV6_GROUP
508 # group_no: 20
509 # ipv6:
510 # addresses:
511 # - 2001:DB8:20::1/64
512 # autoconfig: true
513 # mac_address: 0000.0000.0014
514 # priority: 120
515 # version: 2
516 # - delay:
517 # minimum: 100
518 # reload: 200
519 # name: Vlan100
520 # standby_options:
521 # - group_name: BACKUP_GROUP
522 # group_no: 5
523 # ip:
524 # - virtual_ip: 192.168.1.1
525 # preempt:
526 # enabled: true
527 # priority: 150
528 # track:
529 # - decrement: 30
530 # track_no: 10
531 # version: 2
532
533 # After state:
534 # ------------
535 #
536 # Router#show running-config | section ^interface
537 # interface GigabitEthernet1
538 # ip address dhcp
539 # negotiation auto
540 # !
541 # interface GigabitEthernet2
542 # no ip address
543 # standby 2 ip 172.16.2.1 secondary
544 # standby 2 authentication md5 key-chain AUTH_CHAIN
545 # shutdown
546 # negotiation auto
547 # !
548 # interface GigabitEthernet3
549 # no ip address
550 # standby 1 ip 172.16.1.1
551 # shutdown
552 # negotiation auto
553 # !
554 # interface GigabitEthernet4
555 # no ip address
556 # shutdown
557 # negotiation auto
558 # !
559 # interface Vlan70
560 # description for test
561 # no ip address
562 # standby mac-refresh 45
563 # standby redirect timers 10 55
564 # standby delay minimum 5555 reload 556
565 # standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
566 # standby version 2
567 # standby 10 ip 10.0.10.2 secondary
568 # standby 10 follow MASTER_GROUP
569 # standby 10 priority 110
570 # standby 10 preempt delay minimum 100 reload 50 sync 30
571 # standby 10 authentication md5 key-string 7 0123456789ABCDEF
572 # standby 10 name PRIMARY_GROUP
573 # standby 10 track 1 decrement 20
574 # standby 20 ipv6 autoconfig
575 # standby 20 ipv6 2001:DB8:20::1/64
576 # standby 20 follow MASTER_GROUP
577 # standby 20 priority 120
578 # standby 20 name IPV6_GROUP
579 # standby 20 mac-address 0000.0000.0014
580 # !
581 # interface Vlan100
582 # description for test
583 # no ip address
584 # standby delay minimum 100 reload 200
585 # standby version 2
586 # standby 5 ip 192.168.1.1
587 # standby 5 priority 150
588 # standby 5 preempt
589 # standby 5 name BACKUP_GROUP
590 # standby 5 track 10 decrement 30
591 # !
592
593
594 # Using replaced
595
596 # Before state:
597 # -------------
598 #
599 # Router#show running-config | section ^interface
600 # interface Loopback888
601 # no ip address
602 # interface Loopback999
603 # no ip address
604 # interface GigabitEthernet1
605 # description Management interface do not change
606 # ip address dhcp
607 # negotiation auto
608 # interface GigabitEthernet2
609 # no ip address
610 # speed 1000
611 # no negotiation auto
612 # interface GigabitEthernet3
613 # no ip address
614 # speed 1000
615 # standby 22 ip 10.0.0.1 secondary
616 # no negotiation auto
617 # interface GigabitEthernet4
618 # no ip address
619 # standby 0 priority 5
620 # shutdown
621 # negotiation auto
622
623 - name: Replaces device configuration of listed interfaces with provided configuration
624 cisco.ios.ios_hsrp_interfaces:
625 config:
626 - name: GigabitEthernet3
627 standby_groups:
628 - group_no: 22
629 ip:
630 - virtual_ip: 10.0.0.1
631 secondary: true
632 - name: GigabitEthernet4
633 standby_groups:
634 - group_no: 0
635 priority: 6
636 state: replaced
637
638 # Task Output
639 # -----------
640 #
641 # before:
642 # - name: GigabitEthernet1
643 # - name: GigabitEthernet2
644 # - name: GigabitEthernet3
645 # standby_groups:
646 # - group_no: 22
647 # ip:
648 # - virtual_ip: 192.168.0.2
649 # secondary: True
650 # - name: GigabitEthernet4
651 # standby_groups:
652 # - group_no: 0
653 # priority: 6
654 # - name: Loopback999
655 # - name: Loopback888
656 # commands:
657 # - interface GigabitEthernet3
658 # - standby 22 ip 10.0.0.1 secondary
659 # - interface GigabitEthernet4
660 # - standby 0 priority 5
661 # after:
662 # name: GigabitEthernet1
663 # name: GigabitEthernet2
664 # name: GigabitEthernet3
665 # standby_groups:
666 # - group_no: 22
667 # ip:
668 # - virtual_ip: 192.168.0.2
669 # secondary: True
670 # - name: GigabitEthernet4
671 # standby_groups:
672 # - group_no: 0
673 # priority: 6
674 # - name: Loopback999
675 # - name: Loopback888
676
677 # After state:
678 # ------------
679 #
680 # interface Loopback888
681 # no ip address
682 # interface Loopback999
683 # no ip address
684 # interface GigabitEthernet1
685 # description Management interface do not change
686 # ip address dhcp
687 # negotiation auto
688 # interface GigabitEthernet2
689 # no ip address
690 # ip ospf network broadcast
691 # ip ospf resync-timeout 10
692 # ip ospf dead-interval 5
693 # speed 1000
694 # no negotiation auto
695 # interface GigabitEthernet3
696 # no ip address
697 # standby 22 ip 10.0.0.1 secondary
698 # speed 1000
699 # no negotiation auto
700 # interface GigabitEthernet4
701 # description Auto_Cable_Testing_Ansible
702 # no ip address
703 # standby 0 priority 6
704 # shutdown
705 # negotiation auto
706
707 # Using overridden
708
709 # Before state:
710 # -------------
711 #
712 # interface Loopback888
713 # no ip address
714 # interface Loopback999
715 # no ip address
716 # interface GigabitEthernet1
717 # description Management interface do not change
718 # ip address dhcp
719 # negotiation auto
720 # interface GigabitEthernet2
721 # no ip address
722 # ip ospf network broadcast
723 # ip ospf resync-timeout 10
724 # ip ospf dead-interval 5
725 # speed 1000
726 # no negotiation auto
727 # interface GigabitEthernet3
728 # no ip address
729 # standby 22 ip 10.0.0.1 secondary
730 # speed 1000
731 # no negotiation auto
732 # interface GigabitEthernet4
733 # description Auto_Cable_Testing_Ansible
734 # no ip address
735 # standby 0 priority 6
736 # shutdown
737 # negotiation auto
738
739 - name: Override device configuration of all interfaces with provided configuration
740 cisco.ios.ios_hsrp_interfaces:
741 config:
742 - name: GigabitEthernet4
743 standby_groups:
744 - group_no: 0
745 priority: 10
746 state: overridden
747
748 # Task Output
749 # -----------
750 # before:
751 # - name: GigabitEthernet1
752 # - name: GigabitEthernet2
753 # - name: GigabitEthernet3
754 # standby_groups:
755 # - group_no: 22
756 # ip:
757 # - virtual_ip: 192.168.0.2
758 # secondary: True
759 # - name: GigabitEthernet4
760 # standby_groups:
761 # - group_no: 0
762 # priority: 6
763 # - name: Loopback999
764 # - name: Loopback888
765 # commands:
766 # - interface GigabitEthernet3
767 # - no standby 22 ip 10.0.0.1 secondary
768 # - interface GigabitEthernet4
769 # - no standby 0 priority 6
770 # - standby 0 priority 10
771 # after:
772 # - name: GigabitEthernet1
773 # - name: GigabitEthernet2
774 # - name: GigabitEthernet3
775 # - name: GigabitEthernet4
776 # standby_groups:
777 # - group_no: 0
778 # priority: 10
779 # - name: Loopback999
780 # - name: Loopback888
781
782 # After state:
783 # ------------
784 #
785 # router-ios#show running-config | section ^interface
786 # interface Loopback888
787 # no ip address
788 # interface Loopback999
789 # no ip address
790 # interface GigabitEthernet1
791 # description Management interface do not change
792 # ip address dhcp
793 # negotiation auto
794 # interface GigabitEthernet2
795 # no ip address
796 # ip ospf network broadcast
797 # ip ospf resync-timeout 10
798 # ip ospf dead-interval 5
799 # speed 1000
800 # no negotiation auto
801 # interface GigabitEthernet3
802 # no ip address
803 # speed 1000
804 # no negotiation auto
805 # interface GigabitEthernet4
806 # description Auto_Cable_Testing_Ansible
807 # no ip address
808 # standby 0 priority 10
809 # shutdown
810 # negotiation auto
811
812 # Using deleted
813
814 # Before state:
815 # -------------
816 #
817 # router-ios#show running-config | section ^interface
818 # interface GigabitEthernet1
819 # ip address dhcp
820 # negotiation auto
821 # !
822 # interface GigabitEthernet2
823 # no ip address
824 # standby 2 ip 172.16.2.1 secondary
825 # standby 2 authentication md5 key-chain AUTH_CHAIN
826 # shutdown
827 # negotiation auto
828 # !
829 # interface GigabitEthernet3
830 # no ip address
831 # standby 1 ip 172.16.1.1
832 # shutdown
833 # negotiation auto
834 # !
835 # interface GigabitEthernet4
836 # no ip address
837 # shutdown
838 # negotiation auto
839 # !
840 # interface Vlan70
841 # description for test
842 # no ip address
843 # standby mac-refresh 45
844 # standby redirect timers 10 55
845 # standby delay minimum 5555 reload 556
846 # standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
847 # standby version 2
848 # standby 10 ip 10.0.10.2 secondary
849 # standby 10 follow MASTER_GROUP
850 # standby 10 priority 110
851 # standby 10 preempt delay minimum 100 reload 50 sync 30
852 # standby 10 authentication md5 key-string 7 0123456789ABCDEF
853 # standby 10 name PRIMARY_GROUP
854 # standby 10 track 1 decrement 20
855 # standby 20 ipv6 autoconfig
856 # standby 20 ipv6 2001:DB8:20::1/64
857 # standby 20 follow MASTER_GROUP
858 # standby 20 priority 120
859 # standby 20 name IPV6_GROUP
860 # standby 20 mac-address 0000.0000.0014
861 # !
862 # interface Vlan100
863 # description for test
864 # no ip address
865 # standby delay minimum 100 reload 200
866 # standby version 2
867 # standby 5 ip 192.168.1.1
868 # standby 5 priority 150
869 # standby 5 preempt
870 # standby 5 name BACKUP_GROUP
871 # standby 5 track 10 decrement 30
872
873
874 - name: "Delete attributes of given interfaces (NOTE: This won't delete the interfaces)"
875 cisco.ios.ios_hsrp_interfaces:
876 state: deleted
877
878 # Task Output
879 # -----------
880 #
881 # before:
882 # - name: GigabitEthernet1
883 # - name: GigabitEthernet2
884 # standby_options:
885 # - authentication:
886 # key_chain: AUTH_CHAIN
887 # group_no: 2
888 # ip:
889 # - secondary: true
890 # virtual_ip: 172.16.2.1
891 # priority: 100
892 # - name: GigabitEthernet3
893 # standby_options:
894 # - group_no: 1
895 # ip:
896 # - virtual_ip: 172.16.1.1
897 # priority: 100
898 # - name: GigabitEthernet4
899 # - delay:
900 # minimum: 5555
901 # reload: 556
902 # mac_refresh: 45
903 # name: Vlan70
904 # redirect:
905 # advertisement:
906 # authentication:
907 # key_chain: HSRP_CHAIN
908 # timers:
909 # adv_timer: 10
910 # holddown_timer: 55
911 # standby_options:
912 # - authentication:
913 # encryption: 7
914 # key_string: 0123456789ABCDEF
915 # follow: MASTER_GROUP
916 # group_name: PRIMARY_GROUP
917 # group_no: 10
918 # ip:
919 # - secondary: true
920 # virtual_ip: 10.0.10.2
921 # preempt:
922 # delay: true
923 # enabled: true
924 # minimum: 100
925 # reload: 50
926 # sync: 30
927 # priority: 110
928 # track:
929 # - decrement: 20
930 # track_no: 1
931 # - follow: MASTER_GROUP
932 # group_name: IPV6_GROUP
933 # group_no: 20
934 # ipv6:
935 # addresses:
936 # - 2001:DB8:20::1/64
937 # autoconfig: true
938 # mac_address: 0000.0000.0014
939 # priority: 120
940 # version: 2
941 # - delay:
942 # minimum: 100
943 # reload: 200
944 # name: Vlan100
945 # standby_options:
946 # - group_name: BACKUP_GROUP
947 # group_no: 5
948 # ip:
949 # - virtual_ip: 192.168.1.1
950 # preempt:
951 # enabled: true
952 # priority: 150
953 # track:
954 # - decrement: 30
955 # track_no: 10
956 # version: 2
957 # commands:
958 # - interface GigabitEthernet2
959 # - no standby version 1
960 # - no standby 2
961 # - interface GigabitEthernet3
962 # - no standby version 1
963 # - no standby 1
964 # - interface Vlan70
965 # - no standby version 2
966 # - no standby delay minimum 5555 reload 556
967 # - no standby mac-refresh 45
968 # - no standby redirect timers 10 55
969 # - no standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
970 # - no standby 10
971 # - no standby 20
972 # - no standby version 2
973 # - interface Vlan100
974 # - no standby version 2
975 # - no standby delay minimum 100 reload 200
976 # - no standby 5
977 # - no standby version 2
978 # after:
979 # - name: GigabitEthernet1
980 # - name: GigabitEthernet2
981 # - name: GigabitEthernet3
982 # - name: GigabitEthernet4
983 # - name: Vlan70
984 # - name: Vlan100
985
986 # After state:
987 # -------------
988 #
989 # router-ios#show running-config | section ^interface
990 # !
991 # interface GigabitEthernet1
992 # ip address dhcp
993 # negotiation auto
994 # !
995 # interface GigabitEthernet2
996 # no ip address
997 # shutdown
998 # negotiation auto
999 # !
1000 # interface GigabitEthernet3
1001 # no ip address
1002 # shutdown
1003 # negotiation auto
1004 # !
1005 # interface GigabitEthernet4
1006 # no ip address
1007 # shutdown
1008 # negotiation auto
1009 # !
1010 # interface Vlan70
1011 # description for test
1012 # no ip address
1013 # !
1014 # interface Vlan100
1015 # description for test
1016 # no ip address
1017 # !
1018
1019 # Using gathered
1020
1021 # Before state:
1022 # -------------
1023 # router-ios#show running-config | section ^interface
1024 # interface GigabitEthernet1
1025 # ip address dhcp
1026 # negotiation auto
1027 # !
1028 # interface GigabitEthernet2
1029 # no ip address
1030 # standby 2 ip 172.16.2.1 secondary
1031 # standby 2 authentication md5 key-chain AUTH_CHAIN
1032 # shutdown
1033 # negotiation auto
1034 # !
1035 # interface GigabitEthernet3
1036 # no ip address
1037 # standby 1 ip 172.16.1.1
1038 # shutdown
1039 # negotiation auto
1040 # !
1041 # interface GigabitEthernet4
1042 # no ip address
1043 # shutdown
1044 # negotiation auto
1045 # !
1046 # interface Vlan70
1047 # description for test
1048 # no ip address
1049 # standby mac-refresh 45
1050 # standby redirect timers 10 55
1051 # standby delay minimum 5555 reload 556
1052 # standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
1053 # standby version 2
1054 # standby 10 ip 10.0.10.2 secondary
1055 # standby 10 follow MASTER_GROUP
1056 # standby 10 priority 110
1057 # standby 10 preempt delay minimum 100 reload 50 sync 30
1058 # standby 10 authentication md5 key-string 7 0123456789ABCDEF
1059 # standby 10 name PRIMARY_GROUP
1060 # standby 10 track 1 decrement 20
1061 # standby 20 ipv6 autoconfig
1062 # standby 20 ipv6 2001:DB8:20::1/64
1063 # standby 20 follow MASTER_GROUP
1064 # standby 20 priority 120
1065 # standby 20 name IPV6_GROUP
1066 # standby 20 mac-address 0000.0000.0014
1067 # !
1068 # interface Vlan100
1069 # description for test
1070 # no ip address
1071 # standby delay minimum 100 reload 200
1072 # standby version 2
1073 # standby 5 ip 192.168.1.1
1074 # standby 5 priority 150
1075 # standby 5 preempt
1076 # standby 5 name BACKUP_GROUP
1077 # standby 5 track 10 decrement 30
1078
1079 - name: Gather facts for hsrp interfaces
1080 cisco.ios.ios_hsrp_interfaces:
1081 state: gathered
1082
1083 # Task Output
1084 # -----------
1085 #
1086 # gathered:
1087 # - name: GigabitEthernet1
1088 # - name: GigabitEthernet2
1089 # standby_options:
1090 # - authentication:
1091 # key_chain: AUTH_CHAIN
1092 # group_no: 2
1093 # ip:
1094 # - secondary: true
1095 # virtual_ip: 172.16.2.1
1096 # priority: 100
1097 # - name: GigabitEthernet3
1098 # standby_options:
1099 # - group_no: 1
1100 # ip:
1101 # - virtual_ip: 172.16.1.1
1102 # priority: 100
1103 # - name: GigabitEthernet4
1104 # - delay:
1105 # minimum: 5555
1106 # reload: 556
1107 # mac_refresh: 45
1108 # name: Vlan70
1109 # redirect:
1110 # advertisement:
1111 # authentication:
1112 # key_chain: HSRP_CHAIN
1113 # timers:
1114 # adv_timer: 10
1115 # holddown_timer: 55
1116 # standby_options:
1117 # - authentication:
1118 # encryption: 7
1119 # key_string: 0123456789ABCDEF
1120 # follow: MASTER_GROUP
1121 # group_name: PRIMARY_GROUP
1122 # group_no: 10
1123 # ip:
1124 # - secondary: true
1125 # virtual_ip: 10.0.10.2
1126 # preempt:
1127 # delay: true
1128 # enabled: true
1129 # minimum: 100
1130 # reload: 50
1131 # sync: 30
1132 # priority: 110
1133 # track:
1134 # - decrement: 20
1135 # track_no: 1
1136 # - follow: MASTER_GROUP
1137 # group_name: IPV6_GROUP
1138 # group_no: 20
1139 # ipv6:
1140 # addresses:
1141 # - 2001:DB8:20::1/64
1142 # autoconfig: true
1143 # mac_address: 0000.0000.0014
1144 # priority: 120
1145 # version: 2
1146 # - delay:
1147 # minimum: 100
1148 # reload: 200
1149 # name: Vlan100
1150 # standby_options:
1151 # - group_name: BACKUP_GROUP
1152 # group_no: 5
1153 # ip:
1154 # - virtual_ip: 192.168.1.1
1155 # preempt:
1156 # enabled: true
1157 # priority: 150
1158 # track:
1159 # - decrement: 30
1160 # track_no: 10
1161 # version: 2
1162
1163 # Using rendered
1164
1165 - name: Render the commands for provided configuration
1166 cisco.ios.ios_hsrp_interfaces:
1167 config:
1168 - delay:
1169 minimum: 5555
1170 reload: 556
1171 mac_refresh: 45
1172 name: Vlan70
1173 redirect:
1174 advertisement:
1175 authentication:
1176 key_chain: HSRP_CHAIN
1177 timers:
1178 adv_timer: 10
1179 holddown_timer: 55
1180 standby_options:
1181 - authentication:
1182 encryption: 7
1183 key_string: 0123456789ABCDEF
1184 follow: MASTER_GROUP
1185 group_name: PRIMARY_GROUP
1186 group_no: 10
1187 ip:
1188 - virtual_ip: 10.0.10.1
1189 - secondary: true
1190 virtual_ip: 10.0.10.2
1191 - secondary: true
1192 virtual_ip: 10.0.10.3
1193 mac_address: 0000.0c07.ac0a
1194 preempt:
1195 delay: true
1196 enabled: true
1197 minimum: 100
1198 reload: 50
1199 sync: 30
1200 priority: 110
1201 timers:
1202 hold_time: 250
1203 msec:
1204 hello_interval: 200
1205 track:
1206 - decrement: 20
1207 track_no: 1
1208 - shutdown: true
1209 track_no: 2
1210 - follow: MASTER_GROUP
1211 group_name: IPV6_GROUP
1212 group_no: 20
1213 ipv6:
1214 addresses:
1215 - 2001:db8:10::1/64
1216 - 2001:db8:20::1/64
1217 autoconfig: true
1218 mac_address: 0000.0c07.ac14
1219 priority: 120
1220 version: 2
1221 - delay:
1222 minimum: 100
1223 reload: 200
1224 name: Vlan100
1225 standby_options:
1226 - authentication:
1227 password_text: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
1228 group_name: BACKUP_GROUP
1229 group_no: 5
1230 ip:
1231 - virtual_ip: 192.168.1.1
1232 preempt:
1233 enabled: true
1234 priority: 150
1235 timers:
1236 hello_interval: 5
1237 hold_time: 15
1238 track:
1239 - decrement: 30
1240 track_no: 10
1241 version: 2
1242 - name: GigabitEthernet3
1243 standby_options:
1244 - group_no: 1
1245 ip:
1246 - virtual_ip: 172.16.1.1
1247 priority: 100
1248 use_bia:
1249 set: true
1250 - name: GigabitEthernet2
1251 standby_options:
1252 - authentication:
1253 key_chain: AUTH_CHAIN
1254 group_no: 2
1255 ip:
1256 - secondary: true
1257 virtual_ip: 172.16.2.1
1258 priority: 100
1259 state: rendered
1260
1261 # Task Output
1262 # -----------
1263 #
1264 # rendered:
1265 # - interface Vlan70
1266 # - standby version 2
1267 # - standby delay minimum 5555 reload 556
1268 # - standby mac-refresh 45
1269 # - standby redirect timers 10 55
1270 # - standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
1271 # - standby 10 follow MASTER_GROUP
1272 # - standby 10 mac-address 0000.0c07.ac0a
1273 # - standby 10 name PRIMARY_GROUP
1274 # - standby 10 preempt delay minimum 100 reload 50 sync 30
1275 # - standby 10 priority 110
1276 # - standby 10 authentication md5 key-string 7 0123456789ABCDEF
1277 # - standby 10 ip 10.0.10.1
1278 # - standby 10 ip 10.0.10.2 secondary
1279 # - standby 10 ip 10.0.10.3 secondary
1280 # - standby 10 track 1 decrement 20
1281 # - standby 10 track 2 shutdown
1282 # - standby 20 follow MASTER_GROUP
1283 # - standby 20 mac-address 0000.0c07.ac14
1284 # - standby 20 name IPV6_GROUP
1285 # - standby 20 priority 120
1286 # - standby 20 ipv6 autoconfig
1287 # - standby 20 ipv6 2001:db8:10::1/64
1288 # - standby 20 ipv6 2001:db8:20::1/64
1289 # - interface Vlan100
1290 # - standby version 2
1291 # - standby delay minimum 100 reload 200
1292 # - standby 5 name BACKUP_GROUP
1293 # - standby 5 preempt
1294 # - standby 5 priority 150
1295 # - standby 5 authentication ********
1296 # - standby 5 ip 192.168.1.1
1297 # - standby 5 track 10 decrement 30
1298 # - interface GigabitEthernet3
1299 # - standby version 1
1300 # - standby use-bia scope interface
1301 # - standby 1 priority 100
1302 # - standby 1 ip 172.16.1.1
1303 # - interface GigabitEthernet2
1304 # - standby version 1
1305 # - standby 2 priority 100
1306 # - standby 2 authentication md5 key-chain AUTH_CHAIN
1307 # - standby 2 ip 172.16.2.1 secondary
1308
1309 # Using parsed
1310
1311 # File: parsed.cfg
1312 # ----------------
1313 #
1314 # interface Vlan70
1315 # no ip address
1316 # standby mac-refresh 45
1317 # standby redirect timers 10 55
1318 # standby delay minimum 5555 reload 556
1319 # standby redirect advertisement authentication md5 key-chain HSRP_CHAIN
1320 # standby version 2
1321 # standby 10 ip 10.0.10.1
1322 # standby 10 ip 10.0.10.2 secondary
1323 # standby 10 ip 10.0.10.3 secondary
1324 # standby 10 follow MASTER_GROUP
1325 # standby 10 timers msec 200 250
1326 # standby 10 priority 110
1327 # standby 10 preempt delay minimum 100 reload 50 sync 30
1328 # standby 10 authentication md5 key-string 7 0123456789ABCDEF
1329 # standby 10 name PRIMARY_GROUP
1330 # standby 10 mac-address 0000.0c07.ac0a
1331 # standby 10 track 1 decrement 20
1332 # standby 10 track 2 shutdown
1333 # standby 20 ipv6 2001:db8:10::1/64
1334 # standby 20 ipv6 2001:db8:20::1/64
1335 # standby 20 ipv6 autoconfig
1336 # standby 20 follow MASTER_GROUP
1337 # standby 20 priority 120
1338 # standby 20 name IPV6_GROUP
1339 # standby 20 mac-address 0000.0c07.ac14
1340
1341 # interface Vlan100
1342 # no ip address
1343 # standby bfd
1344 # standby delay minimum 100 reload 200
1345 # standby version 2
1346 # standby 5 ip 192.168.1.1
1347 # standby 5 timers 5 15
1348 # standby 5 priority 150
1349 # standby 5 preempt
1350 # standby 5 authentication hello_secret
1351 # standby 5 name BACKUP_GROUP
1352 # standby 5 track 10 decrement 30
1353
1354 # interface GigabitEthernet3
1355 # standby use-bia
1356 # standby 1 ip 172.16.1.1
1357 # standby 1 priority 100
1358
1359 # interface GigabitEthernet2
1360 # standby follow VLAN70_GROUP
1361 # standby 2 ip 172.16.2.1 secondary
1362 # standby 2 authentication md5 key-chain AUTH_CHAIN
1363
1364 # - name: Parse the provided configuration
1365 # cisco.ios.ios_hsrp_interfaces:
1366 # running_config: "{{ lookup('file', 'parsed.cfg') }}"
1367 # state: parsed
1368
1369 # Task Output
1370 # -----------
1371 #
1372 # parsed:
1373 # - delay:
1374 # minimum: 5555
1375 # reload: 556
1376 # mac_refresh: 45
1377 # name: Vlan70
1378 # redirect:
1379 # advertisement:
1380 # authentication:
1381 # key_chain: HSRP_CHAIN
1382 # timers:
1383 # adv_timer: 10
1384 # holddown_timer: 55
1385 # standby_options:
1386 # - authentication:
1387 # encryption: 7
1388 # key_string: 0123456789ABCDEF
1389 # follow: MASTER_GROUP
1390 # group_name: PRIMARY_GROUP
1391 # group_no: 10
1392 # ip:
1393 # - virtual_ip: 10.0.10.1
1394 # - secondary: true
1395 # virtual_ip: 10.0.10.2
1396 # - secondary: true
1397 # virtual_ip: 10.0.10.3
1398 # mac_address: 0000.0c07.ac0a
1399 # preempt:
1400 # delay: true
1401 # enabled: true
1402 # minimum: 100
1403 # reload: 50
1404 # sync: 30
1405 # priority: 110
1406 # timers:
1407 # hold_time: 250
1408 # msec:
1409 # hello_interval: 200
1410 # track:
1411 # - decrement: 20
1412 # track_no: 1
1413 # - shutdown: true
1414 # track_no: 2
1415 # - follow: MASTER_GROUP
1416 # group_name: IPV6_GROUP
1417 # group_no: 20
1418 # ipv6:
1419 # addresses:
1420 # - 2001:db8:10::1/64
1421 # - 2001:db8:20::1/64
1422 # autoconfig: true
1423 # mac_address: 0000.0c07.ac14
1424 # priority: 120
1425 # version: 2
1426 # - delay:
1427 # minimum: 100
1428 # reload: 200
1429 # name: Vlan100
1430 # standby_options:
1431 # - authentication:
1432 # password_text: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
1433 # group_name: BACKUP_GROUP
1434 # group_no: 5
1435 # ip:
1436 # - virtual_ip: 192.168.1.1
1437 # preempt:
1438 # enabled: true
1439 # priority: 150
1440 # timers:
1441 # hello_interval: 5
1442 # hold_time: 15
1443 # track:
1444 # - decrement: 30
1445 # track_no: 10
1446 # version: 2
1447 # - name: GigabitEthernet3
1448 # standby_options:
1449 # - group_no: 1
1450 # ip:
1451 # - virtual_ip: 172.16.1.1
1452 # priority: 100
1453 # use_bia:
1454 # set: true
1455 # - name: GigabitEthernet2
1456 # standby_options:
1457 # - authentication:
1458 # key_chain: AUTH_CHAIN
1459 # group_no: 2
1460 # ip:
1461 # - secondary: true
1462 # virtual_ip: 172.16.2.1
1463 # priority: 100
1464 """
1465
1466 RETURN = """
1467 before:
1468 description: The configuration prior to the module execution.
1469 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1470 type: dict
1471 sample: >
1472 This output will always be in the same format as the
1473 module argspec.
1474 after:
1475 description: The resulting configuration after module execution.
1476 returned: when changed
1477 type: dict
1478 sample: >
1479 This output will always be in the same format as the
1480 module argspec.
1481 commands:
1482 description: The set of commands pushed to the remote device.
1483 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1484 type: list
1485 sample:
1486 - standby 22 ip 10.0.0.1 secondary
1487 - standby 0 priority 5
1488 - standby mac-refresh 21
1489 rendered:
1490 description: The provided configuration in the task rendered in device-native format (offline).
1491 returned: when I(state) is C(rendered)
1492 type: list
1493 sample:
1494 - standby 22 ip 10.0.0.1 secondary
1495 - standby 0 priority 5
1496 - standby mac-refresh 21
1497 gathered:
1498 description: Facts about the network resource gathered from the remote device as structured data.
1499 returned: when I(state) is C(gathered)
1500 type: list
1501 sample: >
1502 This output will always be in the same format as the
1503 module argspec.
1504 parsed:
1505 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
1506 returned: when I(state) is C(parsed)
1507 type: list
1508 sample: >
1509 This output will always be in the same format as the
1510 module argspec.
1511 """
1512
1513 from ansible.module_utils.basic import AnsibleModule
1514
1515 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.hsrp_interfaces.hsrp_interfaces import (
1516 Hsrp_interfacesArgs,
1517 )
1518 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.hsrp_interfaces.hsrp_interfaces import (
1519 Hsrp_interfaces,
1520 )
1521
1522
1523 def main():
1524 """
1525 Main entry point for module execution
1526
1527 :returns: the result form module invocation
1528 """
1529 module = AnsibleModule(
1530 argument_spec=Hsrp_interfacesArgs.argument_spec,
1531 mutually_exclusive=[["config", "running_config"]],
1532 required_if=[
1533 ["state", "merged", ["config"]],
1534 ["state", "replaced", ["config"]],
1535 ["state", "overridden", ["config"]],
1536 ["state", "rendered", ["config"]],
1537 ["state", "parsed", ["running_config"]],
1538 ],
1539 supports_check_mode=True,
1540 )
1541
1542 result = Hsrp_interfaces(module).execute_module()
1543 module.exit_json(**result)
1544
1545
1546 if __name__ == "__main__":
1547 main()