Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_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_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_interfaces
18 short_description: Resource module to configure interfaces.
19 description: This module manages the interface attributes of Cisco IOS network devices.
20 version_added: 1.0.0
21 author:
22 - Sumit Jaiswal (@justjais)
23 - Sagar Paul (@KB-perByte)
24 notes:
25 - Tested against Cisco IOSXE Version 17.3 on CML.
26 - This module works with connection C(network_cli).
27 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
28 - The module examples uses callback plugin (stdout_callback = yaml) to generate task
29 output in yaml format.
30 options:
31 config:
32 description: A dictionary of interface options
33 type: list
34 elements: dict
35 suboptions:
36 name:
37 description:
38 - Full name of interface, e.g. GigabitEthernet0/2, loopback999.
39 type: str
40 required: true
41 description:
42 description:
43 - Interface description.
44 type: str
45 enabled:
46 description:
47 - Administrative state of the interface.
48 - Set the value to C(true) to administratively enable the interface or C(false)
49 to disable it.
50 type: bool
51 speed:
52 description:
53 - Interface link speed. Applicable for Ethernet interfaces only.
54 type: str
55 mtu:
56 description:
57 - MTU for a specific interface. Applicable for Ethernet interfaces only.
58 - Refer to vendor documentation for valid values.
59 type: int
60 mode:
61 description:
62 - Manage Layer2 or Layer3 state of the interface.
63 - For a Layer 2 appliance mode Layer2 adds switchport command ( default impacts idempotency).
64 - For a Layer 2 appliance mode Layer3 adds no switchport command.
65 - For a Layer 3 appliance mode Layer3/2 has no impact rather command fails on apply.
66 choices:
67 - layer2
68 - layer3
69 type: str
70 duplex:
71 description:
72 - Interface link status. Applicable for Ethernet interfaces only, either in
73 half duplex, full duplex or in automatic state which negotiates the duplex
74 automatically.
75 type: str
76 choices:
77 - full
78 - half
79 - auto
80 template:
81 description:
82 - IOS template name.
83 type: str
84 mac_address:
85 description:
86 - H.H.H MAC address.
87 type: str
88 service_policy:
89 description:
90 - Service policy configuration
91 type: dict
92 suboptions:
93 input:
94 description:
95 - Assign policy-map to the input of an interface
96 type: str
97 output:
98 description:
99 - Assign policy-map to the output of an interface
100 type: str
101 type_options:
102 description:
103 - Configure CPL Service Policy
104 type: dict
105 suboptions:
106 access_control:
107 description: access-control specific policy-map
108 type: dict
109 suboptions:
110 input:
111 description:
112 - Assign policy-map to the input of an interface
113 type: str
114 output:
115 description:
116 - Assign policy-map to the output of an interface
117 type: str
118 epbr:
119 description: Configure ePBR Service Policy
120 type: dict
121 suboptions:
122 input:
123 description:
124 - Assign policy-map to the input of an interface
125 type: str
126 output:
127 description:
128 - Assign policy-map to the output of an interface
129 type: str
130 nwpi:
131 description: Configure Network Wide Path Insight Service Policy
132 type: dict
133 suboptions:
134 input:
135 description:
136 - Assign policy-map to the input of an interface
137 type: str
138 output:
139 description:
140 - Assign policy-map to the output of an interface
141 type: str
142 packet_service:
143 description: Configure Packet-Service Service Policy
144 type: dict
145 suboptions:
146 input:
147 description:
148 - Assign policy-map to the input of an interface
149 type: str
150 output:
151 description:
152 - Assign policy-map to the output of an interface
153 type: str
154 service_chain:
155 description: Configure Service-chain Service Policy
156 type: dict
157 suboptions:
158 input:
159 description:
160 - Assign policy-map to the input of an interface
161 type: str
162 output:
163 description:
164 - Assign policy-map to the output of an interface
165 type: str
166 logging:
167 description:
168 - Logging interface events
169 type: dict
170 suboptions:
171 bundle_status:
172 description:
173 - BUNDLE/UNBUNDLE messages
174 type: bool
175 link_status:
176 description:
177 - UPDOWN and CHANGE messages
178 type: bool
179 nfas_status:
180 description:
181 - NFAS D-channel status messages
182 type: bool
183 spanning_tree:
184 description:
185 - Spanning-tree Interface events
186 type: bool
187 status:
188 description:
189 - Spanning-tree state change messages
190 type: bool
191 subif_link_status:
192 description:
193 - Sub-interface UPDOWN and CHANGE messages
194 type: bool
195 trunk_status:
196 description:
197 - TRUNK status messages
198 type: bool
199 snmp:
200 description:
201 - snmp trap configurations
202 type: dict
203 suboptions:
204 trap:
205 description:
206 - Allow a specific SNMP trap
207 type: dict
208 suboptions:
209 ip:
210 description: internet protocol (snmp trap ip verify drop-rate)
211 type: bool
212 link_status:
213 description: Allow SNMP LINKUP and LINKDOWN traps (snmp trap link-status permit duplicates)
214 type: bool
215 mac_notification_added:
216 description: MAC Address notification for the interface (snmp trap mac-notification change added)
217 type: bool
218 mac_notification_removed:
219 description: MAC Address notification for the interface (snmp trap mac-notification change removed)
220 type: bool
221 ifindex:
222 description:
223 - Persist ifindex for the interface
224 type: dict
225 suboptions:
226 clear:
227 description: Clear Enable/Disable ifIndex persistence
228 type: bool
229 persist:
230 description: Enable/Disable ifIndex persistence
231 type: bool
232 running_config:
233 description:
234 - This option is used only with state I(parsed).
235 - The value of this option should be the output received from the IOS device by
236 executing the command B(show running-config | section ^interface).
237 - The state I(parsed) reads the configuration from C(running_config) option and
238 transforms it into Ansible structured data as per the resource module's argspec
239 and the value is then returned in the I(parsed) key within the result.
240 type: str
241 state:
242 choices:
243 - merged
244 - replaced
245 - overridden
246 - deleted
247 - rendered
248 - gathered
249 - purged
250 - parsed
251 default: merged
252 description:
253 - The state the configuration should be left in
254 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
255 on the device.
256 - The state I(rendered) will transform the configuration in C(config) option to
257 platform specific CLI commands which will be returned in the I(rendered) key
258 within the result. For state I(rendered) active connection to remote host is
259 not required.
260 - The state I(gathered) will fetch the running configuration from device and transform
261 it into structured data in the format as per the resource module argspec and
262 the value is returned in the I(gathered) key within the result.
263 - The state I(parsed) reads the configuration from C(running_config) option and
264 transforms it into JSON format as per the resource module parameters and the
265 value is returned in the I(parsed) key within the result. The value of C(running_config)
266 option should be the same format as the output of command I(show running-config
267 | include ip route|ipv6 route) executed on device. For state I(parsed) active
268 connection to remote host is not required.
269 - The state I(purged) negates virtual/logical interfaces that are specified in task
270 from running-config.
271 type: str
272 """
273
274 EXAMPLES = """
275 # Using merged
276
277 # Before state:
278 # -------------
279 #
280 # Router#sh running-config | section interface
281 # interface Loopback888
282 # no ip address
283 # interface Loopback999
284 # no ip address
285 # interface GigabitEthernet1
286 # ip address dhcp
287 # negotiation auto
288 # interface GigabitEthernet2
289 # description Configured and Merged by Ansible Network
290 # ip address dhcp
291 # speed 1000
292 # no negotiation auto
293 # interface GigabitEthernet3
294 # no ip address
295 # speed 1000
296 # no negotiation auto
297 # interface GigabitEthernet4
298 # no ip address
299 # shutdown
300 # negotiation auto
301
302 - name: Merge provided configuration with device configuration
303 cisco.ios.ios_interfaces:
304 config:
305 - name: GigabitEthernet2
306 description: Configured and Merged by Ansible Network
307 enabled: true
308 - name: GigabitEthernet3
309 description: Configured and Merged by Ansible Network
310 mtu: 3800
311 enabled: false
312 speed: 100
313 duplex: full
314 state: merged
315
316 # Task Output
317 # -----------
318 #
319 # before:
320 # - enabled: true
321 # name: GigabitEthernet1
322 # - description: Configured and Merged by Ansible Network
323 # enabled: true
324 # name: GigabitEthernet2
325 # speed: '1000'
326 # - description: Configured and Merged by Ansible Network
327 # enabled: false
328 # mtu: 3800
329 # name: GigabitEthernet3
330 # speed: '1000'
331 # - enabled: false
332 # name: GigabitEthernet4
333 # - enabled: true
334 # name: Loopback888
335 # - enabled: true
336 # name: Loopback999
337 # commands:
338 # - interface GigabitEthernet3
339 # - description Configured and Merged by Ansible Network
340 # - speed 100
341 # - mtu 3800
342 # - duplex full
343 # - shutdown
344 # after:
345 # - enabled: true
346 # name: GigabitEthernet1
347 # - description: Configured and Merged by Ansible Network
348 # enabled: true
349 # name: GigabitEthernet2
350 # speed: '1000'
351 # - description: Configured and Merged by Ansible Network
352 # enabled: true
353 # mtu: 2800
354 # name: GigabitEthernet3
355 # speed: '1000'
356 # - enabled: false
357 # name: GigabitEthernet4
358 # - enabled: true
359 # name: Loopback888
360 # - enabled: true
361 # name: Loopback999
362
363 # After state:
364 # ------------
365 #
366 # Router#show running-config | section ^interface
367 # interface Loopback888
368 # no ip address
369 # interface Loopback999
370 # no ip address
371 # interface GigabitEthernet1
372 # ip address dhcp
373 # negotiation auto
374 # interface GigabitEthernet2
375 # description Configured and Merged by Ansible Network
376 # ip address dhcp
377 # speed 1000
378 # no negotiation auto
379 # interface GigabitEthernet3
380 # description Configured and Merged by Ansible Network
381 # mtu 3800
382 # no ip address
383 # shutdown
384 # speed 1000
385 # no negotiation auto
386 # interface GigabitEthernet4
387 # no ip address
388 # shutdown
389 # negotiation auto
390
391 # Using merged - with mode attribute
392
393 # Before state:
394 # -------------
395 #
396 # vios#show running-config | section ^interface
397 # interface GigabitEthernet1
398 # description Configured by Ansible
399 # interface GigabitEthernet2
400 # description This is test
401 # interface GigabitEthernet3
402 # description This is test
403 # no switchport
404
405 - name: Merge provided configuration with device configuration
406 cisco.ios.ios_interfaces:
407 config:
408 - name: GigabitEthernet2
409 description: Configured and Merged by Ansible Network
410 enabled: true
411 mode: layer2
412 - name: GigabitEthernet3
413 description: Configured and Merged by Ansible Network
414 mode: layer3
415 state: merged
416
417 # Task Output
418 # -----------
419 #
420 # before:
421 # - enabled: true
422 # name: GigabitEthernet1
423 # - description: Configured and Merged by Ansible Network
424 # name: GigabitEthernet2
425 # - description: Configured and Merged by Ansible Network
426 # name: GigabitEthernet3
427 # commands:
428 # - interface GigabitEthernet2
429 # - description Configured and Merged by Ansible Network
430 # - switchport
431 # - interface GigabitEthernet3
432 # - description Configured and Merged by Ansible Network
433 # after:
434 # - enabled: true
435 # name: GigabitEthernet1
436 # - description: Configured and Merged by Ansible Network
437 # enabled: true
438 # name: GigabitEthernet2
439 # - description: Configured and Merged by Ansible Network
440 # name: GigabitEthernet3
441 # mode: layer3
442
443 # After state:
444 # ------------
445 #
446 # vios#show running-config | section ^interface
447 # interface GigabitEthernet1
448 # description Configured by Ansible
449 # interface GigabitEthernet2
450 # description Configured and Merged by Ansible Network
451 # interface GigabitEthernet3
452 # description Configured and Merged by Ansible Network
453 # no switchport
454
455 # Using replaced
456
457 # Before state:
458 # -------------
459 #
460 # vios#show running-config | section ^interface
461 # interface Loopback888
462 # no ip address
463 # interface Loopback999
464 # no ip address
465 # interface GigabitEthernet1
466 # description Management interface do not change
467 # ip address dhcp
468 # negotiation auto
469 # interface GigabitEthernet2
470 # ip address dhcp
471 # speed 1000
472 # no negotiation auto
473 # interface GigabitEthernet3
474 # no ip address
475 # speed 1000
476 # no negotiation auto
477 # interface GigabitEthernet4
478 # no ip address
479 # shutdown
480 # negotiation auto
481 # interface Vlan50
482 # ip address dhcp hostname testHostname
483
484 - name: Replaces device configuration of listed interfaces with provided configuration
485 cisco.ios.ios_interfaces:
486 config:
487 - name: GigabitEthernet3
488 description: Configured and Replaced by Ansible Network
489 enabled: false
490 speed: 1000
491 state: replaced
492
493 # Task Output
494 # -----------
495 #
496 # before:
497 # - description: Management interface do not change
498 # enabled: true
499 # name: GigabitEthernet1
500 # - enabled: true
501 # name: GigabitEthernet2
502 # speed: '1000'
503 # - enabled: true
504 # name: GigabitEthernet3
505 # speed: '1000'
506 # - enabled: false
507 # name: GigabitEthernet4
508 # - enabled: true
509 # name: Loopback888
510 # - enabled: true
511 # name: Loopback999
512 # - enabled: true
513 # name: Vlan50
514 # commands:
515 # - interface GigabitEthernet3
516 # - description Configured and Replaced by Ansible Network
517 # - shutdown
518 # after:
519 # - description: Management interface do not change
520 # enabled: true
521 # name: GigabitEthernet1
522 # - enabled: true
523 # name: GigabitEthernet2
524 # speed: '1000'
525 # - description: Configured and Replaced by Ansible Network
526 # enabled: false
527 # name: GigabitEthernet3
528 # speed: '1000'
529 # - enabled: false
530 # name: GigabitEthernet4
531 # - enabled: true
532 # name: Loopback888
533 # - enabled: true
534 # name: Loopback999
535 # - enabled: true
536 # name: Vlan50
537
538 # After state:
539 # -------------
540 #
541 # vios#show running-config | section ^interface
542 # interface Loopback888
543 # no ip address
544 # interface Loopback999
545 # no ip address
546 # interface GigabitEthernet1
547 # description Management interface do not change
548 # ip address dhcp
549 # negotiation auto
550 # interface GigabitEthernet2
551 # ip address dhcp
552 # speed 1000
553 # no negotiation auto
554 # interface GigabitEthernet3
555 # description Configured and Replaced by Ansible Network
556 # no ip address
557 # shutdown
558 # speed 1000
559 # no negotiation auto
560 # interface GigabitEthernet4
561 # no ip address
562 # shutdown
563 # negotiation auto
564 # interface Vlan50
565 # ip address dhcp hostname testHostname
566
567 # Using overridden
568
569 # Before state:
570 # -------------
571 #
572 # vios#show running-config | section ^interface
573 # interface Loopback888
574 # no ip address
575 # interface Loopback999
576 # no ip address
577 # interface GigabitEthernet1
578 # description Management interface do not change
579 # ip address dhcp
580 # negotiation auto
581 # interface GigabitEthernet2
582 # ip address dhcp
583 # speed 1000
584 # no negotiation auto
585 # interface GigabitEthernet3
586 # description Configured and Replaced by Ansible Network
587 # no ip address
588 # shutdown
589 # speed 1000
590 # no negotiation auto
591 # interface GigabitEthernet4
592 # no ip address
593 # shutdown
594 # negotiation auto
595 # interface Vlan50
596 # ip address dhcp hostname testHostname
597
598 - name: Override device configuration of all interfaces with provided configuration
599 cisco.ios.ios_interfaces:
600 config:
601 - description: Management interface do not change
602 enabled: true
603 name: GigabitEthernet1
604 - name: GigabitEthernet2
605 description: Configured and Overridden by Ansible Network
606 speed: 10000
607 - name: GigabitEthernet3
608 description: Configured and Overridden by Ansible Network
609 enabled: false
610 state: overridden
611
612 # Task Output
613 # -----------
614 #
615 # before:
616 # - description: Management interface do not change
617 # enabled: true
618 # name: GigabitEthernet1
619 # - enabled: true
620 # name: GigabitEthernet2
621 # speed: '1000'
622 # - description: Configured and Replaced by Ansible Network
623 # enabled: false
624 # name: GigabitEthernet3
625 # speed: '1000'
626 # - enabled: false
627 # name: GigabitEthernet4
628 # - enabled: true
629 # name: Loopback888
630 # - enabled: true
631 # name: Loopback999
632 # - enabled: true
633 # name: Vlan50
634 # commands:
635 # - interface loopback888
636 # - shutdown
637 # - interface loopback999
638 # - shutdown
639 # - interface Vlan50
640 # - shutdown
641 # - interface GigabitEthernet2
642 # - description Configured and Overridden by Ansible Network
643 # - speed 10000
644 # - interface GigabitEthernet3
645 # - description Configured and Overridden by Ansible Network
646 # - no speed 1000
647 # after:
648 # - description: Management interface do not change
649 # enabled: true
650 # name: GigabitEthernet1
651 # - description: Configured and Overridden by Ansible Network
652 # enabled: true
653 # name: GigabitEthernet2
654 # speed: '10000'
655 # - description: Configured and Overridden by Ansible Network
656 # enabled: false
657 # name: GigabitEthernet3
658 # speed: '1000'
659 # - enabled: false
660 # name: GigabitEthernet4
661 # - enabled: false
662 # name: Loopback888
663 # - enabled: false
664 # name: Loopback999
665 # - enabled: false
666 # name: Vlan50
667
668 # After state:
669 # -------------
670 #
671 # vios#show running-config | section ^interface
672 # interface Loopback888
673 # no ip address
674 # shutdown
675 # interface Loopback999
676 # no ip address
677 # shutdown
678 # interface GigabitEthernet1
679 # description Management interface do not change
680 # ip address dhcp
681 # negotiation auto
682 # interface GigabitEthernet2
683 # description Configured and Overridden by Ansible Network
684 # ip address dhcp
685 # speed 10000
686 # no negotiation auto
687 # interface GigabitEthernet3
688 # description Configured and Overridden by Ansible Network
689 # no ip address
690 # shutdown
691 # speed 1000
692 # no negotiation auto
693 # interface GigabitEthernet4
694 # no ip address
695 # shutdown
696 # negotiation auto
697 # interface Vlan50
698 # ip address dhcp hostname testHostname
699 # shutdown
700
701 # Using Deleted
702
703 # Before state:
704 # -------------
705 #
706 # vios#show running-config | section ^interface
707 # interface Loopback888
708 # no ip address
709 # shutdown
710 # interface Loopback999
711 # no ip address
712 # shutdown
713 # interface GigabitEthernet1
714 # description Management interface do not change
715 # ip address dhcp
716 # negotiation auto
717 # interface GigabitEthernet2
718 # description Configured and Overridden by Ansible Network
719 # ip address dhcp
720 # speed 10000
721 # no negotiation auto
722 # interface GigabitEthernet3
723 # description Configured and Overridden by Ansible Network
724 # no ip address
725 # shutdown
726 # speed 1000
727 # no negotiation auto
728 # interface GigabitEthernet4
729 # no ip address
730 # shutdown
731 # negotiation auto
732 # interface Vlan50
733 # ip address dhcp hostname testHostname
734 # shutdown
735
736 - name: "Delete interface attributes (Note: This won't delete the interface itself)"
737 cisco.ios.ios_interfaces:
738 config:
739 - name: GigabitEthernet2
740 state: deleted
741
742 # Task Output
743 # -----------
744 #
745 # before:
746 # - description: Management interface do not change
747 # enabled: true
748 # name: GigabitEthernet1
749 # - description: Configured and Overridden by Ansible Network
750 # enabled: true
751 # name: GigabitEthernet2
752 # speed: '10000'
753 # - description: Configured and Overridden by Ansible Network
754 # enabled: false
755 # name: GigabitEthernet3
756 # speed: '1000'
757 # - enabled: false
758 # name: GigabitEthernet4
759 # - enabled: false
760 # name: Loopback888
761 # - enabled: false
762 # name: Loopback999
763 # - enabled: false
764 # name: Vlan50
765 # commands:
766 # - interface GigabitEthernet2
767 # - no description Configured and Overridden by Ansible Network
768 # - no speed 10000
769 # - shutdown
770 # after:
771 # - description: Management interface do not change
772 # enabled: true
773 # name: GigabitEthernet1
774 # - enabled: false
775 # name: GigabitEthernet2
776 # speed: '1000'
777 # - description: Configured and Overridden by Ansible Network
778 # enabled: false
779 # name: GigabitEthernet3
780 # speed: '1000'
781 # - enabled: false
782 # name: GigabitEthernet4
783 # - enabled: false
784 # name: Loopback888
785 # - enabled: false
786 # name: Loopback999
787 # - enabled: false
788 # name: Vlan50
789
790 # After state:
791 # -------------
792 #
793 # vios#show running-config | section ^interface
794 # interface Loopback888
795 # no ip address
796 # shutdown
797 # interface Loopback999
798 # no ip address
799 # shutdown
800 # interface GigabitEthernet1
801 # description Management interface do not change
802 # ip address dhcp
803 # negotiation auto
804 # interface GigabitEthernet2
805 # ip address dhcp
806 # shutdown
807 # speed 1000
808 # no negotiation auto
809 # interface GigabitEthernet3
810 # description Configured and Overridden by Ansible Network
811 # no ip address
812 # shutdown
813 # speed 1000
814 # no negotiation auto
815 # interface GigabitEthernet4
816 # no ip address
817 # shutdown
818 # negotiation auto
819 # interface Vlan50
820 # ip address dhcp hostname testHostname
821 # shutdown
822
823 # Using Purged
824
825 # Before state:
826 # -------------
827 #
828 # vios#show running-config | section ^interface
829 # interface Loopback888
830 # no ip address
831 # shutdown
832 # interface Loopback999
833 # no ip address
834 # shutdown
835 # interface GigabitEthernet1
836 # description Management interface do not change
837 # ip address dhcp
838 # negotiation auto
839 # interface GigabitEthernet2
840 # ip address dhcp
841 # shutdown
842 # speed 1000
843 # no negotiation auto
844 # interface GigabitEthernet3
845 # description Configured and Overridden by Ansible Network
846 # no ip address
847 # shutdown
848 # speed 1000
849 # no negotiation auto
850 # interface GigabitEthernet4
851 # no ip address
852 # shutdown
853 # negotiation auto
854 # interface Vlan50
855 # ip address dhcp hostname testHostname
856 # shutdown
857
858 - name: "Purge given interfaces (Note: This will delete the interface itself)"
859 cisco.ios.ios_interfaces:
860 config:
861 - name: Loopback888
862 - name: Vlan50
863 state: purged
864
865 # Task Output
866 # -----------
867 #
868 # before:
869 # - description: Management interface do not change
870 # enabled: true
871 # name: GigabitEthernet1
872 # - enabled: false
873 # name: GigabitEthernet2
874 # speed: '1000'
875 # - description: Configured and Overridden by Ansible Network
876 # enabled: false
877 # name: GigabitEthernet3
878 # speed: '1000'
879 # - enabled: false
880 # name: GigabitEthernet4
881 # - enabled: false
882 # name: Loopback888
883 # - enabled: false
884 # name: Loopback999
885 # - enabled: false
886 # name: Vlan50
887 # commands:
888 # - no interface loopback888
889 # - no interface Vlan50
890 # after:
891 # - description: Management interface do not change
892 # enabled: true
893 # name: GigabitEthernet1
894 # - enabled: false
895 # name: GigabitEthernet2
896 # speed: '1000'
897 # - description: Configured and Overridden by Ansible Network
898 # enabled: false
899 # name: GigabitEthernet3
900 # speed: '1000'
901 # - enabled: false
902 # name: GigabitEthernet4
903 # - enabled: false
904 # name: Loopback999
905
906 # After state:
907 # -------------
908 #
909 # vios#show running-config | section ^interface
910 # interface Loopback999
911 # no ip address
912 # shutdown
913 # interface GigabitEthernet1
914 # description Management interface do not change
915 # ip address dhcp
916 # negotiation auto
917 # interface GigabitEthernet2
918 # ip address dhcp
919 # shutdown
920 # speed 1000
921 # no negotiation auto
922 # interface GigabitEthernet3
923 # description Configured and Overridden by Ansible Network
924 # no ip address
925 # shutdown
926 # speed 1000
927 # no negotiation auto
928 # interface GigabitEthernet4
929 # no ip address
930 # shutdown
931 # negotiation auto
932
933 # Using gathered
934
935 # Before state:
936 # -------------
937 #
938 # vios#sh running-config | section ^interface
939 # interface Loopback999
940 # no ip address
941 # shutdown
942 # interface GigabitEthernet1
943 # description Management interface do not change
944 # ip address dhcp
945 # negotiation auto
946 # interface GigabitEthernet2
947 # ip address dhcp
948 # shutdown
949 # speed 1000
950 # no negotiation auto
951 # interface GigabitEthernet3
952 # description Configured and Overridden by Ansible Network
953 # no ip address
954 # shutdown
955 # speed 1000
956 # no negotiation auto
957 # interface GigabitEthernet4
958 # no ip address
959 # shutdown
960 # negotiation auto
961
962 - name: Gather facts of interfaces
963 cisco.ios.ios_interfaces:
964 config:
965 state: gathered
966
967 # Task Output
968 # -----------
969 #
970 # gathered:
971 # - description: Management interface do not change
972 # enabled: true
973 # name: GigabitEthernet1
974 # - enabled: false
975 # name: GigabitEthernet2
976 # speed: '1000'
977 # - description: Configured and Overridden by Ansible Network
978 # enabled: false
979 # name: GigabitEthernet3
980 # speed: '1000'
981 # - enabled: false
982 # name: GigabitEthernet4
983 # - enabled: false
984 # name: Loopback999
985
986 # Using rendered
987
988 - name: Render the commands for provided configuration
989 cisco.ios.ios_interfaces:
990 config:
991 - name: GigabitEthernet1
992 description: Configured by Ansible-Network
993 mtu: 110
994 enabled: true
995 duplex: half
996 - name: GigabitEthernet2
997 description: Configured by Ansible-Network
998 mtu: 2800
999 enabled: false
1000 speed: 100
1001 duplex: full
1002 state: rendered
1003
1004 # Task Output
1005 # -----------
1006 #
1007 # rendered:
1008 # - interface GigabitEthernet1
1009 # - description Configured by Ansible-Network
1010 # - mtu 110
1011 # - duplex half
1012 # - no shutdown
1013 # - interface GigabitEthernet2
1014 # - description Configured by Ansible-Network
1015 # - speed 100
1016 # - mtu 2800
1017 # - duplex full
1018 # - shutdown
1019
1020 # Using parsed
1021
1022 # File: parsed.cfg
1023 # ----------------
1024 #
1025 # interface Loopback999
1026 # no ip address
1027 # shutdown
1028 # interface GigabitEthernet1
1029 # description Management interface do not change
1030 # ip address dhcp
1031 # negotiation auto
1032 # interface GigabitEthernet2
1033 # ip address dhcp
1034 # shutdown
1035 # speed 1000
1036 # no negotiation auto
1037 # interface GigabitEthernet3
1038 # description Configured and Overridden by Ansible Network
1039 # no ip address
1040 # shutdown
1041 # speed 1000
1042 # no negotiation auto
1043 # interface GigabitEthernet4
1044 # no ip address
1045 # shutdown
1046 # negotiation auto
1047
1048 - name: Parse the provided configuration
1049 cisco.ios.ios_interfaces:
1050 running_config: "{{ lookup('file', 'parsed.cfg') }}"
1051 state: parsed
1052
1053 # Task Output
1054 # -----------
1055 #
1056 # parsed:
1057 # - description: Management interface do not change
1058 # enabled: true
1059 # name: GigabitEthernet1
1060 # - enabled: false
1061 # name: GigabitEthernet2
1062 # speed: '1000'
1063 # - description: Configured and Overridden by Ansible Network
1064 # enabled: false
1065 # name: GigabitEthernet3
1066 # speed: '1000'
1067 # - enabled: false
1068 # name: GigabitEthernet4
1069 # - enabled: false
1070 # name: Loopback999
1071 """
1072
1073 RETURN = """
1074 before:
1075 description: The configuration prior to the module execution.
1076 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1077 type: dict
1078 sample: >
1079 This output will always be in the same format as the
1080 module argspec.
1081 after:
1082 description: The resulting configuration after module execution.
1083 returned: when changed
1084 type: dict
1085 sample: >
1086 This output will always be in the same format as the
1087 module argspec.
1088 commands:
1089 description: The set of commands pushed to the remote device.
1090 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
1091 type: list
1092 sample:
1093 - interface GigabitEthernet2
1094 - speed 1200
1095 - mtu 1800
1096 rendered:
1097 description: The provided configuration in the task rendered in device-native format (offline).
1098 returned: when I(state) is C(rendered)
1099 type: list
1100 sample:
1101 - interface GigabitEthernet1
1102 - description Interface description
1103 - shutdown
1104 gathered:
1105 description: Facts about the network resource gathered from the remote device as structured data.
1106 returned: when I(state) is C(gathered)
1107 type: list
1108 sample: >
1109 This output will always be in the same format as the
1110 module argspec.
1111 parsed:
1112 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
1113 returned: when I(state) is C(parsed)
1114 type: list
1115 sample: >
1116 This output will always be in the same format as the
1117 module argspec.
1118 """
1119
1120 from ansible.module_utils.basic import AnsibleModule
1121
1122 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.interfaces.interfaces import (
1123 InterfacesArgs,
1124 )
1125 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.interfaces.interfaces import (
1126 Interfaces,
1127 )
1128
1129
1130 def main():
1131 """
1132 Main entry point for module execution
1133
1134 :returns: the result form module invocation
1135 """
1136 module = AnsibleModule(
1137 argument_spec=InterfacesArgs.argument_spec,
1138 mutually_exclusive=[["config", "running_config"]],
1139 required_if=[
1140 ["state", "merged", ["config"]],
1141 ["state", "replaced", ["config"]],
1142 ["state", "overridden", ["config"]],
1143 ["state", "rendered", ["config"]],
1144 ["state", "purged", ["config"]],
1145 ["state", "parsed", ["running_config"]],
1146 ],
1147 supports_check_mode=True,
1148 )
1149
1150 result = Interfaces(module).execute_module()
1151 module.exit_json(**result)
1152
1153
1154 if __name__ == "__main__":
1155 main()