cisco.ios.ios_l3_interfaces 模块 – 配置 L3 接口的资源模块。
注意
此模块是 cisco.ios 集合 (版本 9.0.3) 的一部分。
如果您使用的是 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install cisco.ios
。
要在 playbook 中使用它,请指定:cisco.ios.ios_l3_interfaces
。
cisco.ios 1.0.0 中的新增功能
概要
此模块提供对 Cisco IOS 设备上三层接口的声明式管理。
参数
参数 |
注释 |
---|---|
三层接口选项的字典 |
|
为 VLAN 启用自动状态确定。 选项
|
|
为在 *name* 选项中提到的三层接口设置的 IPv4 地址。地址格式为 <ipv4 地址>/<掩码>,掩码是 0-32 范围内的数字,例如 192.168.0.1/24。 |
|
配置接口的 IPv4 地址。 |
|
通过 DHCP 协商的 IP 地址。 |
|
指定要使用的 client-id。 |
|
启用 dhcp。 选项
|
|
指定 hostname 选项的值。 |
|
配置并指定要通过 DHCP ip 使用的 client-id。注意,此选项仅在将 dhcp 配置为 IP 时才有效。 千兆以太网接口号 此选项已弃用,并替换为接受字典作为输入的 dhcp,此属性将在 2023-08-01 后删除。 |
|
配置并指定通过 DHCP ip 的 hostname 选项的值。注意,此选项仅在将 dhcp 配置为 IP 时才有效。 此选项已弃用,并替换为接受字典作为输入的 dhcp,此属性将在 2023-08-01 后删除。 |
|
从本地 DHCP 池自动配置的 IP 地址。 |
|
将 IP 地址配置为辅助地址。 选项
|
|
启用 IP 处理,无需显式地址 |
|
接口名称 |
|
启用点对点连接 选项
|
|
启用 IP 连接的主机轮询 选项
|
|
为在 *name* 选项中提到的三层接口设置的 IPv6 地址。 地址格式为 <ipv6 地址>/<掩码>,掩码是 0-128 范围内的数字,例如 fd5d:12c9:2201:1::1/64 |
|
配置接口的 IPv6 地址。 |
|
配置为单播 选项
|
|
使用自动配置获取地址。 |
|
插入默认路由。 选项
|
|
启用自动配置。 选项
|
|
使用 CGA 接口标识符 选项
|
|
使用 DHCP 获取 ipv6 地址。 |
|
启用 dhcp。 选项
|
|
启用快速提交。 选项
|
|
在接口上启用 IPv6 选项
|
|
使用 eui-64 接口标识符 选项
|
|
使用链路本地地址 选项
|
|
分段路由子模式 |
|
将命令设置为其默认值。 选项
|
|
启用分段路由。 选项
|
|
设置 ipv6_sr。 选项
|
|
手动设置接口 MAC 地址。 |
|
接口的全名,不包括任何逻辑单元号,即 GigabitEthernet0/1。 |
|
此选项仅与 state *parsed* 一起使用。 此选项的值应是从 IOS 设备通过执行命令 show running-config | section ^interface 收到的输出。 state *parsed* 从 |
|
配置应保留到的状态 状态 *rendered*、*gathered* 和 *parsed* 不会对设备进行任何更改。 状态 *rendered* 将 状态 *gathered* 将从设备获取运行配置,并将其转换为符合资源模块 argspec 格式的结构化数据,并将值返回到结果中的 *gathered* 密钥中。 状态 *parsed* 从 选项
|
备注
注意
在 CML 上针对 Cisco IOS XE 版本 17.3 进行了测试。
在没有 config 的情况下使用 deleted 状态将删除所有接口中的所有 l3 属性。
此模块与连接
network_cli
一起使用。请参见 https://docs.ansible.org.cn/ansible/latest/network/user_guide/platform_ios.html模块示例使用回调插件 (stdout_callback = yaml) 以 yaml 格式生成任务输出。
示例
# Using merged
# Before state:
# -------------
#
# Router#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Merge provided configuration with device configuration
cisco.ios.ios_l3_interfaces:
config:
- name: GigabitEthernet0/1
ipv4:
- address: 192.168.0.1/24
secondary: true
- name: GigabitEthernet2
ipv4:
- address: 192.168.0.2/24
- name: GigabitEthernet3
ipv6:
- address: fd5d:12c9:2201:1::1/64
- name: GigabitEthernet3.100
ipv4:
- address: 192.168.0.3/24
- name: Vlan901
autostate: false
ipv4:
- source_interface:
name: Loopback1
ipv6:
- enable: true
state: merged
# Task Output
# -----------
#
# before:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet4
# - name: Loopback999
# commands:
# - interface GigabitEthernet2
# - ip address 192.168.0.2 255.255.255.0
# - interface GigabitEthernet3
# - ipv6 address fd5d:12c9:2201:1::1/64
# - interface GigabitEthernet3.100
# - ip address 192.168.0.3 255.255.255.0
# - interface Vlan901
# - ip unnumbered Loopback1
# - ipv6 enable
# - no autostate
# after:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.2/24
# name: GigabitEthernet2
# - ipv6:
# - address: FD5D:12C9:2201:1::1/64
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# ipv4:
# - address: 192.168.0.3/24
# - name: GigabitEthernet4
# - name: Loopback999
# ipv4:
# - source_interface:
# name: Loopback1
# ipv6:
# - enable: true
# autostate: false
# - name: Vlan901
# After state:
# ------------
#
# Router#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.2 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# ipv6 address FD5D:12C9:2201:1::1/64
# interface GigabitEthernet3.100
# ip address 192.168.0.3 255.255.255.0
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan901
# ip unnumbered Loopback1
# ipv6 enable
# no autostate
# Using replaced
# Before state:
# -------------
#
# Router#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.2 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# ipv6 address FD5D:12C9:2201:1::1/64
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Replaces device configuration of listed interfaces with provided configuration
cisco.ios.ios_l3_interfaces:
config:
- name: GigabitEthernet2
ipv4:
- address: 192.168.2.0/24
- name: GigabitEthernet3
ipv4:
- dhcp:
client_id: GigabitEthernet2
hostname: test.com
state: replaced
# Task Output
# -----------
#
# before:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.2/24
# name: GigabitEthernet2
# - ipv6:
# - address: FD5D:12C9:2201:1::1/64
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# commands:
# - interface GigabitEthernet2
# - ip address 192.168.0.3 255.255.255.0
# - no ip address 192.168.0.2 255.255.255.0
# - interface GigabitEthernet3
# - ip address dhcp client-id GigabitEthernet2 hostname test.com
# - no ipv6 address fd5d:12c9:2201:1::1/64
# after:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.3/24
# name: GigabitEthernet2
# - ipv4:
# - dhcp:
# client_id: GigabitEthernet2
# enable: true
# hostname: test.com
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# After state:
# ------------
#
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.3 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# ip address dhcp client-id GigabitEthernet2 hostname test.com
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using overridden
# Before state:
# -------------
#
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.3 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# ip address dhcp client-id GigabitEthernet2 hostname test.com
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Override device configuration of all interfaces with provided configuration
cisco.ios.ios_l3_interfaces:
config:
- ipv4:
- dhcp:
enable: true
name: GigabitEthernet1
- name: GigabitEthernet2
ipv4:
- address: 192.168.0.1/24
- name: GigabitEthernet3
state: overridden
# Task Output
# -----------
# before:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.3/24
# name: GigabitEthernet2
# - ipv4:
# - dhcp:
# client_id: GigabitEthernet2
# enable: true
# hostname: test.com
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# commands:
# - interface GigabitEthernet2
# - ip address 192.168.0.1 255.255.255.0
# - no ip address 192.168.0.3 255.255.255.0
# - interface GigabitEthernet3
# - no ip address dhcp client-id GigabitEthernet2 hostname test.com
# after:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.1/24
# name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# After state:
# ------------
#
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.1 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using deleted
# Before state:
# -------------
#
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.1 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: "Delete attributes of given interfaces (NOTE: This won't delete the interfaces)"
cisco.ios.ios_l3_interfaces:
config:
- name: GigabitEthernet2
- name: GigabitEthernet3.100
state: deleted
# Task Output
# -----------
#
# before:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.1/24
# name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# commands:
# - interface GigabitEthernet2
# - no ip address 192.168.0.1 255.255.255.0
# after:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# After state:
# -------------
#
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using deleted without config passed, only interface's configuration will be negated
# Before state:
# -------------
# router-ios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.2 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# ipv6 address FD5D:12C9:2201:1::1/64
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: "Delete L3 config of all interfaces"
cisco.ios.ios_l3_interfaces:
state: deleted
# Task Output
# -----------
#
# before:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.2/24
# name: GigabitEthernet2
# - ipv6:
# - address: FD5D:12C9:2201:1::1/64
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# commands:
# - interface GigabitEthernet1
# - no ip address dhcp
# - interface GigabitEthernet2
# - no ip address 192.168.0.2 255.255.255.0
# - interface GigabitEthernet3
# - no ipv6 address fd5d:12c9:2201:1::1/64
# after:
# - name: GigabitEthernet1
# - name: GigabitEthernet2
# - name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# After state:
# -------------
#
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# negotiation auto
# interface GigabitEthernet2
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using gathered
# Before state:
# -------------
#
# Router#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address 192.168.0.3 255.255.255.0
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# ip address dhcp client-id GigabitEthernet2 hostname test.com
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3.100
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Gather facts for l3 interfaces
cisco.ios.ios_l3_interfaces:
state: gathered
# Task Output
# -----------
#
# gathered:
# - ipv4:
# - dhcp:
# enable: true
# name: GigabitEthernet1
# - ipv4:
# - address: 192.168.0.3/24
# name: GigabitEthernet2
# - ipv4:
# - dhcp:
# client_id: GigabitEthernet2
# enable: true
# hostname: test.com
# name: GigabitEthernet3
# - name: GigabitEthernet3.100
# - name: GigabitEthernet4
# - name: Loopback999
# Using rendered
- name: Render the commands for provided configuration
cisco.ios.ios_l3_interfaces:
config:
- name: GigabitEthernet1
ipv4:
- dhcp:
client_id: GigabitEthernet0/0
hostname: test.com
- name: GigabitEthernet2
ipv4:
- address: 198.51.100.1/24
secondary: true
- address: 198.51.100.2/24
ipv6:
- address: 2001:db8:0:3::/64
state: rendered
# Task Output
# -----------
#
# rendered:
# - interface GigabitEthernet1
# - ip address dhcp client-id GigabitEthernet0/0 hostname test.com
# - interface GigabitEthernet2
# - ip address 198.51.100.1 255.255.255.0 secondary
# - ip address 198.51.100.2 255.255.255.0
# - ipv6 address 2001:db8:0:3::/64
# Using parsed
# File: parsed.cfg
# ----------------
#
# interface GigabitEthernet0/1
# ip address dhcp client-id GigabitEthernet 0/0 hostname test.com
# interface GigabitEthernet0/2
# ip address 198.51.100.1 255.255.255.0
# ip address 198.51.100.2 255.255.255.0 secondary
# ipv6 address 2001:db8:0:3::/64
- name: Parse the provided configuration
cisco.ios.ios_l3_interfaces:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task Output
# -----------
#
# parsed:
# - ipv4:
# - dhcp:
# client_id: GigabitEthernet0/0
# hostname: test.com
# name: GigabitEthernet0/1
# - ipv4:
# - address: 198.51.100.1/24
# secondary: true
# - address: 198.51.100.2/24
# ipv6:
# - address: 2001:db8:0:3::/64
# name: GigabitEthernet0/2
返回值
常见的返回值已在此处记录,以下是此模块特有的字段
键 |
描述 |
---|---|
模块执行后的最终配置。 返回值:发生更改时 示例: |
|
模块执行前的配置。 返回值:当 state 为 merged、replaced、overridden、deleted 或 purged 时 示例: |
|
推送到远程设备的命令集。 返回值:当 state 为 merged、replaced、overridden、deleted 或 purged 时 示例: |
|
从远程设备收集的关于网络资源的结构化数据事实。 返回值:当 state 为 gathered 时 示例: |
|
根据模块argspec将running_config选项中提供的设备原生配置解析为结构化数据。 返回值:当 state 为 parsed 时 示例: |
|
以设备原生格式呈现的任务中提供的配置(离线)。 返回值:当 state 为 rendered 时 示例: |