Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_l3_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_l3_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12
13
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 module: ios_l3_interfaces
18 short_description: Resource module to configure L3 interfaces.
19 description:
20 - This module provides declarative management of Layer-3 interface on Cisco IOS devices.
21 version_added: 1.0.0
22 author:
23 - Sagar Paul (@KB-perByte)
24 - Sumit Jaiswal (@justjais)
25 - Aayush Anand (@AAYUSH2091)
26 notes:
27 - Tested against Cisco IOSXE Version 17.3 on CML.
28 - Using deleted state without config will delete all l3 attributes from all the interfaces.
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-3 interface options
36 type: list
37 elements: dict
38 suboptions:
39 name:
40 description:
41 - Full name of the interface excluding any logical unit number, i.e. GigabitEthernet0/1.
42 type: str
43 required: true
44 autostate:
45 description:
46 - Enable autostate determination for VLAN.
47 type: bool
48 mac_address:
49 description:
50 - Manually set interface MAC address.
51 type: str
52 redirects:
53 description: Enable sending ICMP Redirect messages.
54 type: bool
55 unreachables:
56 description: Enable sending ICMP Unreachable messages.
57 type: bool
58 ipv6_redirects:
59 description: Enable sending ICMP Redirect messages for IPv6.
60 type: bool
61 ipv6_unreachables:
62 description: Enable sending ICMP Unreachable messages for IPv6.
63 type: bool
64 helper_addresses:
65 description: Specify a destination address for UDP broadcasts
66 type: dict
67 suboptions:
68 ipv4:
69 description: List of ipv4 destiantion IPs
70 type: list
71 elements: dict
72 suboptions:
73 destination_ip:
74 description: IP destination address
75 type: str
76 global:
77 description: Helper-address is global
78 type: bool
79 vrf:
80 description: VRF name for helper-address (if different from interface VRF)
81 type: str
82 ipv4:
83 description:
84 - IPv4 address to be set for the Layer-3 interface mentioned in I(name) option.
85 The address format is <ipv4 address>/<mask>, the mask is number in range
86 0-32 eg. 192.168.0.1/24.
87 type: list
88 elements: dict
89 suboptions:
90 address:
91 description:
92 - Configures the IPv4 address for Interface.
93 type: str
94 secondary:
95 description:
96 - Configures the IP address as a secondary address.
97 type: bool
98 dhcp_client:
99 description:
100 - Configures and specifies client-id to use over DHCP ip. Note, This option
101 shall work only when dhcp is configured as IP.
102 - GigabitEthernet interface number
103 - This option is DEPRECATED and is replaced with dhcp which
104 accepts dict as input this attribute will be removed after 2023-08-01.
105 type: str
106 dhcp_hostname:
107 description:
108 - Configures and specifies value for hostname option over DHCP ip. Note,
109 This option shall work only when dhcp is configured as IP.
110 - This option is DEPRECATED and is replaced with dhcp which
111 accepts dict as input this attribute will be removed after 2023-08-01.
112 type: str
113 dhcp:
114 description: IP Address negotiated via DHCP.
115 type: dict
116 suboptions:
117 enable:
118 description: Enable dhcp.
119 type: bool
120 client_id:
121 description: Specify client-id to use.
122 type: str
123 hostname:
124 description: Specify value for hostname option.
125 type: str
126 pool:
127 description: IP Address auto-configured from a local DHCP pool.
128 type: str
129 redirects:
130 description:
131 - Enable sending ICMP Redirect messages.
132 - This option is DEPRECATED and is replaced with redirects at the interface
133 level. This attribute will be removed after 2028-01-30.
134 type: bool
135 unreachables:
136 description:
137 - Enable sending ICMP Unreachable messages.
138 - This option is DEPRECATED and is replaced with unreachables at the interface
139 level. This attribute will be removed after 2028-01-30.
140 type: bool
141 proxy_arp:
142 description: Enable proxy_arp.
143 type: bool
144 mtu:
145 description: Set IP Maximum Transmission Unit.
146 type: int
147 source_interface:
148 description: Enable IP processing without an explicit address
149 type: dict
150 suboptions:
151 name:
152 description: Interface name
153 type: str
154 poll:
155 description: Enable IP connected host polling
156 type: bool
157 point_to_point:
158 description: Enable point-to-point connection
159 type: bool
160 ipv6:
161 description:
162 - IPv6 address to be set for the Layer-3 interface mentioned in I(name) option.
163 - The address format is <ipv6 address>/<mask>, the mask is number in range
164 0-128 eg. fd5d:12c9:2201:1::1/64
165 type: list
166 elements: dict
167 suboptions:
168 address:
169 description:
170 - Configures the IPv6 address for Interface.
171 type: str
172 autoconfig:
173 description: Obtain address using auto-configuration.
174 type: dict
175 suboptions:
176 enable:
177 description: enable auto-configuration.
178 type: bool
179 default:
180 description: Insert default route.
181 type: bool
182 dhcp:
183 description: Obtain a ipv6 address using DHCP.
184 type: dict
185 suboptions:
186 enable:
187 description: Enable dhcp.
188 type: bool
189 rapid_commit:
190 description: Enable Rapid-Commit.
191 type: bool
192 enable:
193 description: Enable IPv6 on interface
194 type: bool
195 anycast:
196 description: Configure as an anycast
197 type: bool
198 cga:
199 description: Use CGA interface identifier
200 type: bool
201 eui:
202 description: Use eui-64 interface identifier
203 type: bool
204 link_local:
205 description: Use link-local address
206 type: bool
207 segment_routing:
208 description: Segment Routing submode
209 type: dict
210 suboptions:
211 enable:
212 description: Enable segmented routing.
213 type: bool
214 default:
215 description: Set a command to its defaults.
216 type: bool
217 ipv6_sr:
218 description: Set ipv6_sr.
219 type: bool
220 running_config:
221 description:
222 - This option is used only with state I(parsed).
223 - The value of this option should be the output received from the IOS device
224 by executing the command B(show running-config | section ^interface).
225 - The state I(parsed) reads the configuration from C(running_config) option and
226 transforms it into Ansible structured data as per the resource module's argspec
227 and the value is then returned in the I(parsed) key within the result.
228 type: str
229 state:
230 choices:
231 - merged
232 - replaced
233 - overridden
234 - deleted
235 - rendered
236 - gathered
237 - parsed
238 default: merged
239 description:
240 - The state the configuration should be left in
241 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
242 on the device.
243 - The state I(rendered) will transform the configuration in C(config) option to
244 platform specific CLI commands which will be returned in the I(rendered) key
245 within the result. For state I(rendered) active connection to remote host is
246 not required.
247 - The state I(gathered) will fetch the running configuration from device and transform
248 it into structured data in the format as per the resource module argspec and
249 the value is returned in the I(gathered) key within the result.
250 - The state I(parsed) reads the configuration from C(running_config) option and
251 transforms it into JSON format as per the resource module parameters and the
252 value is returned in the I(parsed) key within the result. The value of C(running_config)
253 option should be the same format as the output of command
254 I(show running-config | section ^interface) executed on device. For state I(parsed) active
255 connection to remote host is not required.
256 type: str
257 """
258
259 EXAMPLES = """
260 # Using merged
261
262 # Before state:
263 # -------------
264 #
265 # Router#show running-config | section ^interface
266 # interface Loopback999
267 # no ip address
268 # shutdown
269 # interface GigabitEthernet1
270 # description Management interface do not change
271 # ip address dhcp
272 # negotiation auto
273 # interface GigabitEthernet2
274 # ip address dhcp
275 # shutdown
276 # speed 1000
277 # no negotiation auto
278 # interface GigabitEthernet3
279 # description Configured and Overridden by Ansible Network
280 # no ip address
281 # shutdown
282 # speed 1000
283 # no negotiation auto
284 # interface GigabitEthernet4
285 # no ip address
286 # shutdown
287 # negotiation auto
288
289 - name: Merge provided configuration with device configuration
290 cisco.ios.ios_l3_interfaces:
291 config:
292 - name: GigabitEthernet0/1
293 ipv4:
294 - address: 192.168.0.1/24
295 secondary: true
296 - name: GigabitEthernet2
297 helper_addresses:
298 ipv4:
299 - destination_ip: 10.0.0.1
300 - global: true
301 destination_ip: 10.0.0.2
302 ipv4:
303 - address: 192.168.0.2/24
304 - name: GigabitEthernet3
305 ipv6:
306 - address: fd5d:12c9:2201:1::1/64
307 - name: GigabitEthernet3.100
308 ipv4:
309 - address: 192.168.0.3/24
310 - name: Vlan901
311 autostate: false
312 ipv4:
313 - source_interface:
314 name: Loopback1
315 ipv6:
316 - enable: true
317 state: merged
318
319 # Task Output
320 # -----------
321 #
322 # before:
323 # - ipv4:
324 # - dhcp:
325 # enable: true
326 # name: GigabitEthernet1
327 # - ipv4:
328 # - dhcp:
329 # enable: true
330 # name: GigabitEthernet2
331 # - name: GigabitEthernet3
332 # - name: GigabitEthernet4
333 # - name: Loopback999
334 # commands:
335 # - interface GigabitEthernet2
336 # - ip address 192.168.0.2 255.255.255.0
337 # - interface GigabitEthernet3
338 # - ipv6 address fd5d:12c9:2201:1::1/64
339 # - interface GigabitEthernet3.100
340 # - ip address 192.168.0.3 255.255.255.0
341 # - interface Vlan901
342 # - ip unnumbered Loopback1
343 # - ipv6 enable
344 # - no autostate
345 # after:
346 # - ipv4:
347 # - dhcp:
348 # enable: true
349 # name: GigabitEthernet1
350 # - ipv4:
351 # - address: 192.168.0.2/24
352 # name: GigabitEthernet2
353 # helper_addresses:
354 # ipv4:
355 # - destination_ip: 10.0.0.1
356 # - global: true
357 # destination_ip: 10.0.0.2
358 # - ipv6:
359 # - address: FD5D:12C9:2201:1::1/64
360 # name: GigabitEthernet3
361 # - name: GigabitEthernet3.100
362 # ipv4:
363 # - address: 192.168.0.3/24
364 # - name: GigabitEthernet4
365 # - name: Loopback999
366 # ipv4:
367 # - source_interface:
368 # name: Loopback1
369 # ipv6:
370 # - enable: true
371 # autostate: false
372 # - name: Vlan901
373
374 # After state:
375 # ------------
376 #
377 # Router#show running-config | section ^interface
378 # interface Loopback999
379 # no ip address
380 # shutdown
381 # interface GigabitEthernet1
382 # description Management interface do not change
383 # ip address dhcp
384 # negotiation auto
385 # interface GigabitEthernet2
386 # ip address 192.168.0.2 255.255.255.0
387 # ip helper-address 10.0.0.1
388 # ip helper-address global 10.0.0.2
389 # shutdown
390 # speed 1000
391 # no negotiation auto
392 # interface GigabitEthernet3
393 # description Configured and Overridden by Ansible Network
394 # no ip address
395 # shutdown
396 # speed 1000
397 # no negotiation auto
398 # ipv6 address FD5D:12C9:2201:1::1/64
399 # interface GigabitEthernet3.100
400 # ip address 192.168.0.3 255.255.255.0
401 # interface GigabitEthernet4
402 # no ip address
403 # shutdown
404 # negotiation auto
405 # interface Vlan901
406 # ip unnumbered Loopback1
407 # ipv6 enable
408 # no autostate
409
410
411 # Using replaced
412
413 # Before state:
414 # -------------
415 #
416 # Router#show running-config | section ^interface
417 # interface Loopback999
418 # no ip address
419 # shutdown
420 # interface GigabitEthernet1
421 # description Management interface do not change
422 # ip address dhcp
423 # negotiation auto
424 # interface GigabitEthernet2
425 # ip address 192.168.0.2 255.255.255.0
426 # ip helper-address global 10.0.0.1
427 # shutdown
428 # speed 1000
429 # no negotiation auto
430 # interface GigabitEthernet3
431 # description Configured and Overridden by Ansible Network
432 # no ip address
433 # shutdown
434 # speed 1000
435 # no negotiation auto
436 # ipv6 address FD5D:12C9:2201:1::1/64
437 # interface GigabitEthernet3.100
438 # interface GigabitEthernet4
439 # no ip address
440 # shutdown
441 # negotiation auto
442
443 - name: Replaces device configuration of listed interfaces with provided configuration
444 cisco.ios.ios_l3_interfaces:
445 config:
446 - name: GigabitEthernet2
447 helper_addresses:
448 ipv4:
449 - vrf: abc
450 destination_ip: 10.0.0.1
451 ipv4:
452 - address: 192.168.2.0/24
453 - name: GigabitEthernet3
454 ipv4:
455 - dhcp:
456 client_id: GigabitEthernet2
457 hostname: test.com
458 state: replaced
459
460 # Task Output
461 # -----------
462 #
463 # before:
464 # - ipv4:
465 # - dhcp:
466 # enable: true
467 # name: GigabitEthernet1
468 # - ipv4:
469 # - address: 192.168.0.2/24
470 # name: GigabitEthernet2
471 # helper_addresses:
472 # ipv4:
473 # - global: true
474 # destination_ip: 10.0.0.1
475 # - ipv6:
476 # - address: FD5D:12C9:2201:1::1/64
477 # name: GigabitEthernet3
478 # - name: GigabitEthernet3.100
479 # - name: GigabitEthernet4
480 # - name: Loopback999
481 # commands:
482 # - interface GigabitEthernet2
483 # - ip address 192.168.0.3 255.255.255.0
484 # - no ip address 192.168.0.2 255.255.255.0
485 # - no ip helper-address global 10.0.0.1
486 # - ip helper-address vrf abc 10.0.0.1
487 # - interface GigabitEthernet3
488 # - ip address dhcp client-id GigabitEthernet2 hostname test.com
489 # - no ipv6 address fd5d:12c9:2201:1::1/64
490 # after:
491 # - ipv4:
492 # - dhcp:
493 # enable: true
494 # name: GigabitEthernet1
495 # - ipv4:
496 # - address: 192.168.0.3/24
497 # name: GigabitEthernet2
498 # helper_addresses:
499 # ipv4:
500 # - vrf: abc
501 # destination_ip: 10.0.0.1
502 # - ipv4:
503 # - dhcp:
504 # client_id: GigabitEthernet2
505 # enable: true
506 # hostname: test.com
507 # name: GigabitEthernet3
508 # - name: GigabitEthernet3.100
509 # - name: GigabitEthernet4
510 # - name: Loopback999
511
512 # After state:
513 # ------------
514 #
515 # router-ios#show running-config | section ^interface
516 # interface Loopback999
517 # no ip address
518 # shutdown
519 # interface GigabitEthernet1
520 # description Management interface do not change
521 # ip address dhcp
522 # negotiation auto
523 # interface GigabitEthernet2
524 # ip address 192.168.0.3 255.255.255.0
525 # shutdown
526 # speed 1000
527 # no negotiation auto
528 # interface GigabitEthernet3
529 # description Configured and Overridden by Ansible Network
530 # ip address dhcp client-id GigabitEthernet2 hostname test.com
531 # shutdown
532 # speed 1000
533 # no negotiation auto
534 # interface GigabitEthernet3.100
535 # interface GigabitEthernet4
536 # no ip address
537 # shutdown
538 # negotiation auto
539
540 # Using overridden
541
542 # Before state:
543 # -------------
544 #
545 # router-ios#show running-config | section ^interface
546 # interface Loopback999
547 # no ip address
548 # shutdown
549 # interface GigabitEthernet1
550 # description Management interface do not change
551 # ip address dhcp
552 # negotiation auto
553 # interface GigabitEthernet2
554 # ip address 192.168.0.3 255.255.255.0
555 # shutdown
556 # speed 1000
557 # no negotiation auto
558 # interface GigabitEthernet3
559 # description Configured and Overridden by Ansible Network
560 # ip address dhcp client-id GigabitEthernet2 hostname test.com
561 # shutdown
562 # speed 1000
563 # no negotiation auto
564 # interface GigabitEthernet3.100
565 # interface GigabitEthernet4
566 # no ip address
567 # shutdown
568 # negotiation auto
569
570 - name: Override device configuration of all interfaces with provided configuration
571 cisco.ios.ios_l3_interfaces:
572 config:
573 - ipv4:
574 - dhcp:
575 enable: true
576 name: GigabitEthernet1
577 - name: GigabitEthernet2
578 ipv4:
579 - address: 192.168.0.1/24
580 - name: GigabitEthernet3
581 state: overridden
582
583 # Task Output
584 # -----------
585 # before:
586 # - ipv4:
587 # - dhcp:
588 # enable: true
589 # name: GigabitEthernet1
590 # - ipv4:
591 # - address: 192.168.0.3/24
592 # name: GigabitEthernet2
593 # - ipv4:
594 # - dhcp:
595 # client_id: GigabitEthernet2
596 # enable: true
597 # hostname: test.com
598 # name: GigabitEthernet3
599 # - name: GigabitEthernet3.100
600 # - name: GigabitEthernet4
601 # - name: Loopback999
602 # commands:
603 # - interface GigabitEthernet2
604 # - ip address 192.168.0.1 255.255.255.0
605 # - no ip address 192.168.0.3 255.255.255.0
606 # - interface GigabitEthernet3
607 # - no ip address dhcp client-id GigabitEthernet2 hostname test.com
608 # after:
609 # - ipv4:
610 # - dhcp:
611 # enable: true
612 # name: GigabitEthernet1
613 # - ipv4:
614 # - address: 192.168.0.1/24
615 # name: GigabitEthernet2
616 # - name: GigabitEthernet3
617 # - name: GigabitEthernet3.100
618 # - name: GigabitEthernet4
619 # - name: Loopback999
620
621 # After state:
622 # ------------
623 #
624 # router-ios#show running-config | section ^interface
625 # interface Loopback999
626 # no ip address
627 # shutdown
628 # interface GigabitEthernet1
629 # description Management interface do not change
630 # ip address dhcp
631 # negotiation auto
632 # interface GigabitEthernet2
633 # ip address 192.168.0.1 255.255.255.0
634 # shutdown
635 # speed 1000
636 # no negotiation auto
637 # interface GigabitEthernet3
638 # description Configured and Overridden by Ansible Network
639 # no ip address
640 # shutdown
641 # speed 1000
642 # no negotiation auto
643 # interface GigabitEthernet3.100
644 # interface GigabitEthernet4
645 # no ip address
646 # shutdown
647 # negotiation auto
648
649 # Using deleted
650
651 # Before state:
652 # -------------
653 #
654 # router-ios#show running-config | section ^interface
655 # interface Loopback999
656 # no ip address
657 # shutdown
658 # interface GigabitEthernet1
659 # description Management interface do not change
660 # ip address dhcp
661 # negotiation auto
662 # interface GigabitEthernet2
663 # ip address 192.168.0.1 255.255.255.0
664 # shutdown
665 # speed 1000
666 # no negotiation auto
667 # interface GigabitEthernet3
668 # description Configured and Overridden by Ansible Network
669 # no ip address
670 # shutdown
671 # speed 1000
672 # no negotiation auto
673 # interface GigabitEthernet3.100
674 # interface GigabitEthernet4
675 # no ip address
676 # shutdown
677 # negotiation auto
678
679 - name: "Delete attributes of given interfaces (NOTE: This won't delete the interfaces)"
680 cisco.ios.ios_l3_interfaces:
681 config:
682 - name: GigabitEthernet2
683 - name: GigabitEthernet3.100
684 state: deleted
685
686 # Task Output
687 # -----------
688 #
689 # before:
690 # - ipv4:
691 # - dhcp:
692 # enable: true
693 # name: GigabitEthernet1
694 # - ipv4:
695 # - address: 192.168.0.1/24
696 # name: GigabitEthernet2
697 # - name: GigabitEthernet3
698 # - name: GigabitEthernet3.100
699 # - name: GigabitEthernet4
700 # - name: Loopback999
701 # commands:
702 # - interface GigabitEthernet2
703 # - no ip address 192.168.0.1 255.255.255.0
704 # after:
705 # - ipv4:
706 # - dhcp:
707 # enable: true
708 # name: GigabitEthernet1
709 # - name: GigabitEthernet2
710 # - name: GigabitEthernet3
711 # - name: GigabitEthernet3.100
712 # - name: GigabitEthernet4
713 # - name: Loopback999
714
715 # After state:
716 # -------------
717 #
718 # router-ios#show running-config | section ^interface
719 # interface Loopback999
720 # no ip address
721 # shutdown
722 # interface GigabitEthernet1
723 # description Management interface do not change
724 # ip address dhcp
725 # negotiation auto
726 # interface GigabitEthernet2
727 # no ip address
728 # shutdown
729 # speed 1000
730 # no negotiation auto
731 # interface GigabitEthernet3
732 # description Configured and Overridden by Ansible Network
733 # no ip address
734 # shutdown
735 # speed 1000
736 # no negotiation auto
737 # interface GigabitEthernet3.100
738 # interface GigabitEthernet4
739 # no ip address
740 # shutdown
741 # negotiation auto
742
743 # Using deleted without config passed, only interface's configuration will be negated
744
745 # Before state:
746 # -------------
747
748 # router-ios#show running-config | section ^interface
749 # interface Loopback999
750 # no ip address
751 # shutdown
752 # interface GigabitEthernet1
753 # description Management interface do not change
754 # ip address dhcp
755 # negotiation auto
756 # interface GigabitEthernet2
757 # ip address 192.168.0.2 255.255.255.0
758 # shutdown
759 # speed 1000
760 # no negotiation auto
761 # interface GigabitEthernet3
762 # description Configured and Overridden by Ansible Network
763 # no ip address
764 # shutdown
765 # speed 1000
766 # no negotiation auto
767 # ipv6 address FD5D:12C9:2201:1::1/64
768 # interface GigabitEthernet3.100
769 # interface GigabitEthernet4
770 # no ip address
771 # shutdown
772 # negotiation auto
773
774 - name: "Delete L3 config of all interfaces"
775 cisco.ios.ios_l3_interfaces:
776 state: deleted
777
778 # Task Output
779 # -----------
780 #
781 # before:
782 # - ipv4:
783 # - dhcp:
784 # enable: true
785 # name: GigabitEthernet1
786 # - ipv4:
787 # - address: 192.168.0.2/24
788 # name: GigabitEthernet2
789 # - ipv6:
790 # - address: FD5D:12C9:2201:1::1/64
791 # name: GigabitEthernet3
792 # - name: GigabitEthernet3.100
793 # - name: GigabitEthernet4
794 # - name: Loopback999
795 # commands:
796 # - interface GigabitEthernet1
797 # - no ip address dhcp
798 # - interface GigabitEthernet2
799 # - no ip address 192.168.0.2 255.255.255.0
800 # - interface GigabitEthernet3
801 # - no ipv6 address fd5d:12c9:2201:1::1/64
802 # after:
803 # - name: GigabitEthernet1
804 # - name: GigabitEthernet2
805 # - name: GigabitEthernet3
806 # - name: GigabitEthernet3.100
807 # - name: GigabitEthernet4
808 # - name: Loopback999
809
810 # After state:
811 # -------------
812 #
813 # interface Loopback999
814 # no ip address
815 # shutdown
816 # interface GigabitEthernet1
817 # description Management interface do not change
818 # negotiation auto
819 # interface GigabitEthernet2
820 # shutdown
821 # speed 1000
822 # no negotiation auto
823 # interface GigabitEthernet3
824 # description Configured and Overridden by Ansible Network
825 # no ip address
826 # shutdown
827 # speed 1000
828 # no negotiation auto
829 # interface GigabitEthernet3.100
830 # interface GigabitEthernet4
831 # no ip address
832 # shutdown
833 # negotiation auto
834
835 # Using gathered
836
837 # Before state:
838 # -------------
839 #
840 # Router#show running-config | section ^interface
841 # interface Loopback999
842 # no ip address
843 # shutdown
844 # interface GigabitEthernet1
845 # description Management interface do not change
846 # ip address dhcp
847 # negotiation auto
848 # interface GigabitEthernet2
849 # ip address 192.168.0.3 255.255.255.0
850 # shutdown
851 # speed 1000
852 # no negotiation auto
853 # interface GigabitEthernet3
854 # description Configured and Overridden by Ansible Network
855 # ip address dhcp client-id GigabitEthernet2 hostname test.com
856 # shutdown
857 # speed 1000
858 # no negotiation auto
859 # interface GigabitEthernet3.100
860 # interface GigabitEthernet4
861 # no ip address
862 # shutdown
863 # negotiation auto
864
865 - name: Gather facts for l3 interfaces
866 cisco.ios.ios_l3_interfaces:
867 state: gathered
868
869 # Task Output
870 # -----------
871 #
872 # gathered:
873 # - ipv4:
874 # - dhcp:
875 # enable: true
876 # name: GigabitEthernet1
877 # - ipv4:
878 # - address: 192.168.0.3/24
879 # name: GigabitEthernet2
880 # - ipv4:
881 # - dhcp:
882 # client_id: GigabitEthernet2
883 # enable: true
884 # hostname: test.com
885 # name: GigabitEthernet3
886 # - name: GigabitEthernet3.100
887 # - name: GigabitEthernet4
888 # - name: Loopback999
889
890 # Using rendered
891
892 - name: Render the commands for provided configuration
893 cisco.ios.ios_l3_interfaces:
894 config:
895 - name: GigabitEthernet1
896 ipv4:
897 - dhcp:
898 client_id: GigabitEthernet0/0
899 hostname: test.com
900 - name: GigabitEthernet2
901 ipv4:
902 - address: 198.51.100.1/24
903 secondary: true
904 - address: 198.51.100.2/24
905 ipv6:
906 - address: 2001:db8:0:3::/64
907 state: rendered
908
909 # Task Output
910 # -----------
911 #
912 # rendered:
913 # - interface GigabitEthernet1
914 # - ip address dhcp client-id GigabitEthernet0/0 hostname test.com
915 # - interface GigabitEthernet2
916 # - ip address 198.51.100.1 255.255.255.0 secondary
917 # - ip address 198.51.100.2 255.255.255.0
918 # - ipv6 address 2001:db8:0:3::/64
919
920 # Using parsed
921
922 # File: parsed.cfg
923 # ----------------
924 #
925 # interface GigabitEthernet0/1
926 # ip address dhcp client-id GigabitEthernet 0/0 hostname test.com
927 # interface GigabitEthernet0/2
928 # ip address 198.51.100.1 255.255.255.0
929 # ip address 198.51.100.2 255.255.255.0 secondary
930 # ipv6 address 2001:db8:0:3::/64
931
932 - name: Parse the provided configuration
933 cisco.ios.ios_l3_interfaces:
934 running_config: "{{ lookup('file', 'parsed.cfg') }}"
935 state: parsed
936
937 # Task Output
938 # -----------
939 #
940 # parsed:
941 # - ipv4:
942 # - dhcp:
943 # client_id: GigabitEthernet0/0
944 # hostname: test.com
945 # name: GigabitEthernet0/1
946 # - ipv4:
947 # - address: 198.51.100.1/24
948 # secondary: true
949 # - address: 198.51.100.2/24
950 # ipv6:
951 # - address: 2001:db8:0:3::/64
952 # name: GigabitEthernet0/2
953 """
954
955 RETURN = """
956 before:
957 description: The configuration prior to the module execution.
958 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
959 type: dict
960 sample: >
961 This output will always be in the same format as the
962 module argspec.
963 after:
964 description: The resulting configuration after module execution.
965 returned: when changed
966 type: dict
967 sample: >
968 This output will always be in the same format as the
969 module argspec.
970 commands:
971 description: The set of commands pushed to the remote device.
972 returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged)
973 type: list
974 sample:
975 - "ip address 192.168.0.3 255.255.255.0"
976 - "ipv6 address dhcp rapid-commit"
977 - "ipv6 address fd5d:12c9:2201:1::1/64 anycast"
978 rendered:
979 description: The provided configuration in the task rendered in device-native format (offline).
980 returned: when I(state) is C(rendered)
981 type: list
982 sample:
983 - "ipv6 address FD5D:12C9:2201:1::1/64"
984 - "ip address 192.168.0.3 255.255.255.0"
985 - "ip address autoconfig"
986 gathered:
987 description: Facts about the network resource gathered from the remote device as structured data.
988 returned: when I(state) is C(gathered)
989 type: list
990 sample: >
991 This output will always be in the same format as the
992 module argspec.
993 parsed:
994 description: The device native config provided in I(running_config) option parsed into structured data as per module argspec.
995 returned: when I(state) is C(parsed)
996 type: list
997 sample: >
998 This output will always be in the same format as the
999 module argspec.
1000 """
1001
1002 from ansible.module_utils.basic import AnsibleModule
1003
1004 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.l3_interfaces.l3_interfaces import (
1005 L3_interfacesArgs,
1006 )
1007 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.l3_interfaces.l3_interfaces import (
1008 L3_interfaces,
1009 )
1010
1011
1012 def main():
1013 """
1014 Main entry point for module execution
1015
1016 :returns: the result form module invocation
1017 """
1018 module = AnsibleModule(
1019 argument_spec=L3_interfacesArgs.argument_spec,
1020 mutually_exclusive=[["config", "running_config"]],
1021 required_if=[
1022 ["state", "merged", ["config"]],
1023 ["state", "replaced", ["config"]],
1024 ["state", "overridden", ["config"]],
1025 ["state", "rendered", ["config"]],
1026 ["state", "parsed", ["running_config"]],
1027 ],
1028 supports_check_mode=True,
1029 )
1030
1031 result = L3_interfaces(module).execute_module()
1032 module.exit_json(**result)
1033
1034
1035 if __name__ == "__main__":
1036 main()