Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_l2_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_l2_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_l2_interfaces
18 short_description: Resource module to configure L2 interfaces.
19 description:
20 - This module provides declarative management of Layer-2 interface on Cisco
21 IOS devices.
22 version_added: 1.0.0
23 author:
24 - Sagar Paul (@KB-petByte)
25 - Sumit Jaiswal (@justjais)
26 - Nikhil Bhasin (@nickbhasin)
27 notes:
28 - Tested against Cisco IOSv Version 15.2 on CML.
29 - This module works with connection C(network_cli).
30 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
31 - The module examples uses callback plugin (stdout_callback = yaml) to generate task
32 output in yaml format.
33 options:
34 config:
35 description: A dictionary of Layer-2 interface options
36 type: list
37 elements: dict
38 suboptions:
39 name:
40 description:
41 - Full name of the interface excluding any logical unit
42 number, i.e GigabitEthernet0/1.
43 type: str
44 required: true
45 access:
46 description:
47 - Switchport mode access command to configure the interface as a layer 2 access.
48 type: dict
49 suboptions:
50 vlan:
51 description:
52 - Configure given VLAN in access port. It's used as the access VLAN ID.
53 type: int
54 vlan_name:
55 description:
56 - Set VLAN when interface is in access mode.
57 type: str
58 voice:
59 description:
60 - Switchport mode voice command to configure the interface with a voice vlan.
61 type: dict
62 suboptions:
63 vlan:
64 description:
65 - Configure given voice VLAN on access port. It's used as the voice VLAN
66 ID.
67 type: int
68 vlan_tag:
69 description:
70 - Set VLAN Tag.
71 dot1p (Priority tagged on PVID)
72 none (Don't tell telephone about voice vlan)
73 untagged (Untagged on PVID)
74 choices:
75 - dot1p
76 - none
77 - untagged
78 type: str
79 vlan_name:
80 description:
81 - Set VLAN when interface is in access mode.
82 type: str
83 trunk:
84 description:
85 - Switchport mode trunk command to configure the interface as a Layer 2 trunk.
86 Note The encapsulation is always set to dot1q.
87 type: dict
88 suboptions:
89 allowed_vlans:
90 description:
91 - List of allowed VLANs in a given trunk port. These are the only VLANs
92 that will be configured on the trunk.
93 type: list
94 elements: str
95 native_vlan:
96 description:
97 - Native VLAN to be configured in trunk port. It's used as the trunk native
98 VLAN ID.
99 type: int
100 encapsulation:
101 description:
102 - Trunking encapsulation when interface is in trunking mode.
103 choices:
104 - dot1q
105 - isl
106 - negotiate
107 type: str
108 pruning_vlans:
109 description:
110 - Pruning VLAN to be configured in trunk port. It's used as the trunk
111 pruning VLAN ID.
112 type: list
113 elements: str
114 mode:
115 description:
116 - Mode in which interface needs to be configured.
117 - An interface whose trunk encapsulation is "Auto" can not be configured to
118 "trunk" mode.
119 type: str
120 choices:
121 - access
122 - trunk
123 - dot1q_tunnel
124 - dynamic
125 - dynamic_auto
126 - dynamic_desirable
127 - private_vlan_host
128 - private_vlan_promiscuous
129 - private_vlan_trunk
130 xconnect:
131 description:
132 - Configure xconnect reference for the interface.
133 type: dict
134 suboptions:
135 address:
136 description:
137 - Remote peer IP address.
138 type: str
139 vcid:
140 description:
141 - Virtual Circuit ID.
142 type: int
143 encapsulation:
144 description:
145 - Encapsulation type for xconnect.
146 type: str
147 choices:
148 - mpls
149 - l2tpv3
150 manual:
151 description:
152 - Manually configure the xconnect.
153 type: bool
154 pw_class:
155 description:
156 - Pseudowire class name.
157 type: str
158 sequencing:
159 description:
160 - Sequencing options for the xconnect.
161 type: str
162 choices:
163 - both
164 - receive
165 - transmit
166 private_vlan:
167 description:
168 - Set the private VLAN configuration.
169 type: dict
170 suboptions:
171 association:
172 description:
173 - Set the private VLAN association.
174 type: bool
175 host_association:
176 description:
177 - Set the private VLAN host association.
178 type: bool
179 mapping:
180 description:
181 - Set the private VLAN promiscuous mapping.
182 type: bool
183 host:
184 description:
185 - Set the private VLAN host association.
186 type: bool
187 primary_range:
188 description:
189 - Primary extended/normal range VLAN ID of the private VLAN promiscuous port mapping.
190 type: int
191 secondary_range:
192 description:
193 - Secondary extended/normal range VLAN ID of the private VLAN promiscuous port mapping.
194 type: int
195 add:
196 description:
197 - Add a VLAN to private VLAN list.
198 type: bool
199 remove:
200 description:
201 - Remove a VLAN from private VLAN list.
202 type: bool
203 secondary_vlan_id:
204 description:
205 - Secondary VLAN IDs of the private VLAN promiscuous port mapping.
206 type: str
207 app_interface:
208 description:
209 - Enabling port for Application Hosting (switchport app-interface)
210 type: bool
211 nonegotiate:
212 description:
213 - Device will not engage in negotiation protocol on this interface (switchport nonegotiate)
214 type: bool
215 vepa:
216 description:
217 - Reflective relay configuration (switchport vepa enabled)
218 type: bool
219 host:
220 description:
221 - Set port host (switchport host)
222 type: bool
223 protected:
224 description:
225 - Configure an interface to be a protected port (switchport protected)
226 type: bool
227 encapsulation:
228 description:
229 - Configure encapsulation for the interface.
230 type: dict
231 suboptions:
232 type:
233 description:
234 - Encapsulation type (e.g., dot1q).
235 type: str
236 vlan_id:
237 description:
238 - VLAN ID for encapsulation.
239 type: int
240 block_options:
241 description:
242 - Disable forwarding of unknown uni/multi cast addresses.
243 type: dict
244 suboptions:
245 multicast:
246 description:
247 - Block unknown multicast addresses
248 type: bool
249 unicast:
250 description:
251 - Block unknown unicast addresses
252 type: bool
253 spanning_tree:
254 description:
255 - Spanning tree options
256 type: dict
257 suboptions:
258 bpdufilter:
259 description: Don't send or receive BPDUs on this interface
260 type: dict
261 suboptions:
262 enabled:
263 description:
264 - Enable BPDU filtering for this interface
265 type: bool
266 disabled:
267 description:
268 - Disable BPDU filtering for this interface
269 type: bool
270 bpduguard:
271 description: Don't accept BPDUs on this interface
272 type: dict
273 suboptions:
274 enabled:
275 description:
276 - Enable BPDU guard for this interface
277 type: bool
278 disabled:
279 description:
280 - Disable BPDU guard for this interface
281 type: bool
282 cost:
283 description: Change an interface's spanning tree port path cost
284 type: int
285 guard:
286 description: Change an interface's spanning tree guard mode
287 type: dict
288 suboptions:
289 loop:
290 description:
291 - Set guard mode to loop guard on interface
292 type: bool
293 none:
294 description:
295 - Set guard mode to none
296 type: bool
297 root:
298 description:
299 - Set guard mode to root guard on interface
300 type: bool
301 link_type:
302 description: Specify a link type for spanning tree protocol use
303 type: dict
304 suboptions:
305 point_to_point:
306 description:
307 - Consider the interface as point-to-point
308 type: bool
309 shared:
310 description:
311 - Consider the interface as shared
312 type: bool
313 mst:
314 description: Multiple spanning tree
315 type: dict
316 suboptions:
317 instance_range:
318 description:
319 - MST instance list, example 0,2-4,6,8-12
320 type: str
321 cost:
322 description:
323 - <1-200000000> Change the interface spanning tree path cost for an instance
324 type: str
325 port_priority:
326 description:
327 - Change the spanning tree port priority for an instance
328 type: int
329 port_priority:
330 description: Change an interface's spanning tree port priority
331 type: int
332 portfast:
333 description: Enable an interface to move directly to forwarding on link up
334 type: dict
335 suboptions:
336 disabled:
337 description:
338 - Disable portfast for this interface
339 type: bool
340 trunk:
341 description:
342 - Enable portfast on the interface even in trunk mode
343 type: bool
344 rootguard:
345 description: Enable root guard protection on the interface
346 type: bool
347 vlan:
348 description: VLAN Switch Spanning Tree
349 type: dict
350 suboptions:
351 vlan_range:
352 description:
353 - MST instance list, example 1,3-5,7,9-11
354 type: str
355 cost:
356 description:
357 - <1-200000000> Change the interface spanning tree path cost for an instance
358 type: str
359 port_priority:
360 description:
361 - Change the spanning tree port priority for an instance
362 type: int
363 running_config:
364 description:
365 - This option is used only with state I(parsed).
366 - The value of this option should be the output received from the IOS device by
367 executing the command B(show running-config | section ^interface).
368 - The state I(parsed) reads the configuration from C(running_config) option and
369 transforms it into Ansible structured data as per the resource module's argspec
370 and the value is then returned in the I(parsed) key within the result.
371 type: str
372 state:
373 choices:
374 - merged
375 - replaced
376 - overridden
377 - deleted
378 - rendered
379 - gathered
380 - parsed
381 default: merged
382 description:
383 - The state the configuration should be left in
384 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
385 on the device.
386 - The state I(rendered) will transform the configuration in C(config) option to
387 platform specific CLI commands which will be returned in the I(rendered) key
388 within the result. For state I(rendered) active connection to remote host is
389 not required.
390 - The state I(gathered) will fetch the running configuration from device and
391 transform it into structured data in the format as per the resource module
392 argspec and the value is returned in the I(gathered) key within the result.
393 - The state I(parsed) reads the configuration from C(running_config) option and
394 transforms it into JSON format as per the resource module parameters and the
395 value is returned in the I(parsed) key within the result. The value of
396 C(running_config) option should be the same format as the output of
397 command I(show running-config | include ip route|ipv6 route) executed on device.
398 For state I(parsed) active connection to remote host is not required.
399 type: str
400 """
401
402 EXAMPLES = """
403 # Using merged
404
405 # Before state:
406 # -------------
407 #
408 # viosl2#show running-config | section ^interface
409 # interface GigabitEthernet0/1
410 # description Configured by Ansible
411 # negotiation auto
412 # interface GigabitEthernet0/2
413 # description This is test
414 # switchport access vlan 20
415 # media-type rj45
416 # negotiation auto
417
418 - name: Merge provided configuration with device configuration
419 cisco.ios.ios_l2_interfaces:
420 config:
421 - name: GigabitEthernet0/1
422 mode: access
423 access:
424 vlan: 10
425 voice:
426 vlan: 40
427 - name: GigabitEthernet0/2
428 mode: trunk
429 trunk:
430 allowed_vlans: 10-20,40
431 native_vlan: 20
432 pruning_vlans: 10,20
433 encapsulation: dot1q
434 state: merged
435
436 # Task Output
437 # -----------
438 #
439 # before:
440 # - name: GigabitEthernet0/1
441 # - access:
442 # vlan: 20
443 # name: GigabitEthernet0/2
444 # commands:
445 # - interface GigabitEthernet0/1
446 # - switchport access vlan 10
447 # - switchport voice vlan 40
448 # - switchport mode access
449 # - interface GigabitEthernet0/2
450 # - switchport mode trunk
451 # - switchport trunk encapsulation dot1q
452 # - switchport trunk native vlan 20
453 # - switchport trunk allowed vlan 10-20,40
454 # - switchport trunk pruning vlan 10,20
455 # after:
456 # - access:
457 # vlan: 10
458 # mode: access
459 # name: GigabitEthernet0/1
460 # voice:
461 # vlan: 40
462 # - mode: trunk
463 # name: GigabitEthernet0/2
464 # trunk:
465 # allowed_vlans:
466 # - 10-20
467 # - '40'
468 # encapsulation: dot1q
469 # native_vlan: 20
470 # pruning_vlans:
471 # - '10'
472 # - '20'
473
474 # After state:
475 # ------------
476 #
477 # viosl2#show running-config | section ^interface
478 # interface GigabitEthernet0/1
479 # description Configured by Ansible
480 # switchport access vlan 10
481 # switchport voice vlan 40
482 # switchport mode access
483 # negotiation auto
484 # interface GigabitEthernet0/2
485 # description This is test
486 # switchport trunk allowed vlan 10-20,40
487 # switchport trunk encapsulation dot1q
488 # switchport trunk native vlan 20
489 # switchport trunk pruning vlan 10,20
490 # switchport mode trunk
491 # media-type rj45
492 # negotiation auto
493
494 # Using replaced
495
496 # Before state:
497 # -------------
498 #
499 # viosl2#show running-config | section ^interface
500 # interface GigabitEthernet0/1
501 # description Configured by Ansible
502 # switchport access vlan 20
503 # negotiation auto
504 # interface GigabitEthernet0/2
505 # description This is test
506 # switchport access vlan 20
507 # media-type rj45
508 # negotiation auto
509
510 - name: Replaces device configuration with provided configuration
511 cisco.ios.ios_l2_interfaces:
512 config:
513 - name: GigabitEthernet0/2
514 trunk:
515 allowed_vlans: 20-25,40
516 native_vlan: 20
517 pruning_vlans: 10
518 encapsulation: isl
519 state: replaced
520
521 # Task Output
522 # -----------
523 #
524 # before:
525 # - name: GigabitEthernet0/1
526 # - access:
527 # vlan: 20
528 # name: GigabitEthernet0/2
529 # commands:
530 # - interface GigabitEthernet0/2
531 # - no switchport access vlan
532 # - switchport trunk encapsulation isl
533 # - switchport trunk native vlan 20
534 # - switchport trunk allowed vlan 20-25,40
535 # - switchport trunk pruning vlan 10
536 # after:
537 # - access:
538 # vlan: 20
539 # name: GigabitEthernet0/1
540 # - name: GigabitEthernet0/2
541 # trunk:
542 # allowed_vlans:
543 # - 20-25
544 # - '40'
545 # encapsulation: isl
546 # native_vlan: 20
547 # pruning_vlans:
548 # - '10'
549
550 # After state:
551 # -------------
552 #
553 # viosl2#show running-config | section ^interface
554 # interface GigabitEthernet0/1
555 # description Configured by Ansible
556 # switchport access vlan 20
557 # negotiation auto
558 # interface GigabitEthernet0/2
559 # description This is test
560 # switchport trunk allowed vlan 20-25,40
561 # switchport trunk encapsulation isl
562 # switchport trunk native vlan 20
563 # switchport trunk pruning vlan 10
564 # media-type rj45
565 # negotiation auto
566
567 # Using overridden
568
569 # Before state:
570 # -------------
571 #
572 # viosl2#show running-config | section ^interface
573 # interface GigabitEthernet0/1
574 # description Configured by Ansible
575 # switchport trunk encapsulation dot1q
576 # switchport trunk native vlan 20
577 # negotiation auto
578 # interface GigabitEthernet0/2
579 # description This is test
580 # switchport access vlan 20
581 # switchport trunk encapsulation dot1q
582 # switchport trunk native vlan 20
583 # media-type rj45
584 # negotiation auto
585
586 - name: Override device configuration of all l2 interfaces with provided configuration
587 cisco.ios.ios_l2_interfaces:
588 config:
589 - name: GigabitEthernet0/2
590 access:
591 vlan: 20
592 voice:
593 vlan: 40
594 state: overridden
595
596 # Task Output
597 # -----------
598 #
599 # before:
600 # - name: GigabitEthernet0/1
601 # trunk:
602 # encapsulation: dot1q
603 # native_vlan: 20
604 # - access:
605 # vlan: 20
606 # name: GigabitEthernet0/2
607 # trunk:
608 # encapsulation: dot1q
609 # native_vlan: 20
610 # commands:
611 # - interface GigabitEthernet0/1
612 # - no switchport trunk encapsulation
613 # - no switchport trunk native vlan
614 # - interface GigabitEthernet0/2
615 # - switchport voice vlan 40
616 # - no switchport trunk encapsulation
617 # - no switchport trunk native vlan
618 # after:
619 # - name: GigabitEthernet0/1
620 # - access:
621 # vlan: 20
622 # name: GigabitEthernet0/2
623 # voice:
624 # vlan: 40
625
626 # After state:
627 # -------------
628 #
629 # viosl2#show running-config | section ^interface
630 # interface GigabitEthernet0/1
631 # description Configured by Ansible
632 # negotiation auto
633 # interface GigabitEthernet0/2
634 # description This is test
635 # switchport access vlan 20
636 # switchport voice vlan 40
637 # media-type rj45
638 # negotiation auto
639
640 # Using deleted
641
642 # Before state:
643 # -------------
644 #
645 # viosl2#show running-config | section ^interface
646 # interface GigabitEthernet0/1
647 # description Configured by Ansible
648 # switchport access vlan 20
649 # negotiation auto
650 # interface GigabitEthernet0/2
651 # description This is test
652 # switchport access vlan 20
653 # switchport trunk allowed vlan 20-40,60,80
654 # switchport trunk encapsulation dot1q
655 # switchport trunk native vlan 10
656 # switchport trunk pruning vlan 10
657 # media-type rj45
658 # negotiation auto
659
660 - name: Delete IOS L2 interfaces as in given arguments
661 cisco.ios.ios_l2_interfaces:
662 config:
663 - name: GigabitEthernet0/1
664 state: deleted
665
666 # Task Output
667 # -----------
668 #
669 # before:
670 # - access:
671 # vlan: 20
672 # name: GigabitEthernet0/1
673 # - access:
674 # vlan: 20
675 # name: GigabitEthernet0/2
676 # trunk:
677 # allowed_vlans:
678 # - 20-40
679 # - '60'
680 # - '80'
681 # encapsulation: dot1q
682 # native_vlan: 10
683 # pruning_vlans:
684 # - '10'
685 # commands:
686 # - interface GigabitEthernet0/1
687 # - no switchport access vlan
688 # after:
689 # - name: GigabitEthernet0/1
690 # - access:
691 # vlan: 20
692 # name: GigabitEthernet0/2
693 # trunk:
694 # allowed_vlans:
695 # - 20-40
696 # - '60'
697 # - '80'
698 # encapsulation: dot1q
699 # native_vlan: 10
700 # pruning_vlans:
701 # - '10'
702
703 # After state:
704 # -------------
705 #
706 # viosl2#show running-config | section ^interface
707 # interface GigabitEthernet0/1
708 # description Configured by Ansible
709 # negotiation auto
710 # interface GigabitEthernet0/2
711 # description This is test
712 # switchport access vlan 20
713 # switchport trunk allowed vlan 20-40,60,80
714 # switchport trunk encapsulation dot1q
715 # switchport trunk native vlan 10
716 # switchport trunk pruning vlan 10
717 # media-type rj45
718 # negotiation auto
719
720 # Using deleted without config - delete all configuration
721
722 # Before state:
723 # -------------
724 #
725 # viosl2#show running-config | section ^interface
726 # interface GigabitEthernet0/1
727 # description Configured by Ansible
728 # switchport access vlan 20
729 # negotiation auto
730 # interface GigabitEthernet0/2
731 # description This is test
732 # switchport access vlan 20
733 # switchport trunk allowed vlan 20-40,60,80
734 # switchport trunk encapsulation dot1q
735 # switchport trunk native vlan 10
736 # switchport trunk pruning vlan 10
737 # media-type rj45
738 # negotiation auto
739
740 - name: Delete IOS L2 interfaces as in given arguments
741 cisco.ios.ios_l2_interfaces:
742 state: deleted
743
744 # Task Output
745 # -----------
746 #
747 # before:
748 # - access:
749 # vlan: 20
750 # name: GigabitEthernet0/1
751 # - access:
752 # vlan: 20
753 # name: GigabitEthernet0/2
754 # trunk:
755 # allowed_vlans:
756 # - 20-40
757 # - '60'
758 # - '80'
759 # encapsulation: dot1q
760 # native_vlan: 10
761 # pruning_vlans:
762 # - '10'
763 # commands:
764 # - interface GigabitEthernet0/1
765 # - no switchport access vlan
766 # - interface GigabitEthernet0/2
767 # - no switchport access vlan
768 # - no switchport trunk encapsulation
769 # - no switchport trunk native vlan
770 # - no switchport trunk allowed vlan
771 # - no switchport trunk pruning vlan
772 # after:
773 # - name: GigabitEthernet0/1
774 # - name: GigabitEthernet0/2
775
776 # After state:
777 # -------------
778 #
779 # viosl2#show running-config | section ^interface
780 # interface GigabitEthernet0/1
781 # description Configured by Ansible
782 # negotiation auto
783 # interface GigabitEthernet0/2
784 # description This is test
785 # media-type rj45
786 # negotiation auto
787
788 # Using gathered
789
790 # Before state:
791 # -------------
792 #
793 # vios#sh running-config | section ^interface
794 # interface GigabitEthernet0/1
795 # description Configured by Ansible
796 # switchport access vlan 20
797 # negotiation auto
798 # interface GigabitEthernet0/2
799 # description This is test
800 # switchport access vlan 20
801 # switchport trunk allowed vlan 20-40,60,80
802 # switchport trunk encapsulation dot1q
803 # switchport trunk native vlan 10
804 # switchport trunk pruning vlan 10
805 # media-type rj45
806 # negotiation auto
807
808 - name: Gather facts for l2 interfaces
809 cisco.ios.ios_l2_interfaces:
810 config:
811 state: gathered
812
813 # Task Output
814 # -----------
815 #
816 # gathered:
817 # - access:
818 # vlan: 20
819 # name: GigabitEthernet0/1
820 # - access:
821 # vlan: 20
822 # name: GigabitEthernet0/2
823 # trunk:
824 # allowed_vlans:
825 # - 20-40
826 # - '60'
827 # - '80'
828 # encapsulation: dot1q
829 # native_vlan: 10
830 # pruning_vlans:
831 # - '10'
832
833 # Using rendered
834
835 - name: Render the commands for provided configuration
836 cisco.ios.ios_l2_interfaces:
837 config:
838 - name: GigabitEthernet0/1
839 access:
840 vlan: 30
841 - name: GigabitEthernet0/2
842 trunk:
843 allowed_vlans: 10-20,40
844 native_vlan: 20
845 pruning_vlans: 10,20
846 encapsulation: dot1q
847 state: rendered
848
849 # Task Output
850 # -----------
851 #
852 # rendered:
853 # - interface GigabitEthernet0/1
854 # - switchport access vlan 30
855 # - interface GigabitEthernet0/2
856 # - switchport trunk encapsulation dot1q
857 # - switchport trunk native vlan 20
858 # - switchport trunk allowed vlan 10-20,40
859 # - switchport trunk pruning vlan 10,20
860
861 # Using Parsed
862
863 # File: parsed.cfg
864 # ----------------
865 #
866 # interface GigabitEthernet0/1
867 # description Configured by Ansible
868 # switchport access vlan 20
869 # negotiation auto
870 # interface GigabitEthernet0/2
871 # description This is test
872 # switchport access vlan 20
873 # switchport trunk allowed vlan 20-40,60,80
874 # switchport trunk encapsulation dot1q
875 # switchport trunk native vlan 10
876 # switchport trunk pruning vlan 10
877 # media-type rj45
878 # negotiation auto
879
880 - name: Parse the commands for provided configuration
881 cisco.ios.ios_l2_interfaces:
882 running_config: "{{ lookup('file', 'parsed.cfg') }}"
883 state: parsed
884
885 # Task Output
886 # -----------
887 #
888 # parsed:
889 # - access:
890 # vlan: 20
891 # name: GigabitEthernet0/1
892 # - access:
893 # vlan: 20
894 # name: GigabitEthernet0/2
895 # trunk:
896 # allowed_vlans:
897 # - 20-40
898 # - '60'
899 # - '80'
900 # encapsulation: dot1q
901 # native_vlan: 10
902 # pruning_vlans:
903 # - '10'
904 """
905
906 RETURN = """
907 before:
908 description: The configuration prior to the module execution.
909 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
910 type: dict
911 sample: >
912 This output will always be in the same format as the
913 module argspec.
914 after:
915 description: The resulting configuration after module execution.
916 returned: when changed
917 type: dict
918 sample: >
919 This output will always be in the same format as the
920 module argspec.
921 commands:
922 description: The set of commands pushed to the remote device.
923 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
924 type: list
925 sample:
926 - interface GigabitEthernet0/2
927 - switchport trunk allowed vlan 15-20,40
928 - switchport trunk encapsulation dot1q
929 rendered:
930 description: The provided configuration in the task rendered in device-native format (offline).
931 returned: when I(state) is C(rendered)
932 type: list
933 sample:
934 - interface GigabitEthernet0/1
935 - switchport access vlan 30
936 - switchport trunk encapsulation dot1q
937 gathered:
938 description: Facts about the network resource gathered from the remote device as structured data.
939 returned: when I(state) is C(gathered)
940 type: list
941 sample: >
942 This output will always be in the same format as the
943 module argspec.
944 parsed:
945 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
946 returned: when I(state) is C(parsed)
947 type: list
948 sample: >
949 This output will always be in the same format as the
950 module argspec.
951 """
952
953 from ansible.module_utils.basic import AnsibleModule
954
955 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.l2_interfaces.l2_interfaces import (
956 L2_interfacesArgs,
957 )
958 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.l2_interfaces.l2_interfaces import (
959 L2_interfaces,
960 )
961
962
963 def main():
964 """
965 Main entry point for module execution
966
967 :returns: the result form module invocation
968 """
969 module = AnsibleModule(
970 argument_spec=L2_interfacesArgs.argument_spec,
971 mutually_exclusive=[["config", "running_config"]],
972 required_if=[
973 ["state", "merged", ["config"]],
974 ["state", "replaced", ["config"]],
975 ["state", "overridden", ["config"]],
976 ["state", "rendered", ["config"]],
977 ["state", "parsed", ["running_config"]],
978 ],
979 supports_check_mode=True,
980 )
981
982 result = L2_interfaces(module).execute_module()
983 module.exit_json(**result)
984
985
986 if __name__ == "__main__":
987 main()