cisco.iosxr.iosxr_l2_interfaces 模块 – 配置 L2 接口的资源模块。
注意
此模块是 cisco.iosxr 集合 (版本 10.2.2) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install cisco.iosxr
。
要在 playbook 中使用它,请指定: cisco.iosxr.iosxr_l2_interfaces
。
cisco.iosxr 1.0.0 中的新增功能
概要
此模块管理 Cisco IOS-XR 设备上的二层接口属性。
参数
参数 |
注释 |
---|---|
二层接口选项的字典 |
|
指定此子接口将匹配哪些数据包。 |
|
IEEE 802.1Q VLAN 标记的数据包。 |
|
IEEE 802.1Q VLAN 标记的数据包。 |
|
配置接口上的二层协议隧道和协议数据单元 (PDU) 过滤。 |
|
Cisco Discovery Protocol (CDP) 隧道和数据单元参数。 选项
|
|
CDP、PVST+、STP 和 VTP 协议。 选项
|
|
配置每 VLAN 生成树协议 (PVST) 隧道和数据单元参数。 选项
|
|
生成树协议 (STP) 隧道和数据单元参数。 选项
|
|
VLAN Trunk Protocol (VTP) 隧道和数据单元参数。 选项
|
|
Switchport mode access 命令,用于将接口配置为二层访问接口 选项
|
|
接口/子接口的全名,不包括任何逻辑单元号,例如 GigabitEthernet0/0/0/1 或 GigabitEthernet0/0/0/1.100。 |
|
为中继配置原生 VLAN ID |
|
传播二层传输事件。请注意,只有当 *l2tranport* 选项设置为 TRUE 时,它才能工作 选项
|
|
802.1Q VLAN 配置。请注意,在配置 Q-in-Q VLAN 时,它可以接受 2 个 VLAN ID,或者在配置 Q-in-any VLAN 时,它将接受 1 个 VLAN ID 和“any”作为输入列表。请注意,此选项仅对子接口有效,在为接口配置时无效。 此选项已弃用,并替换为 qvlan,此属性将在 2026-06-01 后移除。 |
|
802.1Q VLAN 配置。请注意,在配置 Q-in-Q VLAN 时,它可以接受 2 个 VLAN ID,或者在配置 Q-in-any VLAN 时,它将接受 1 个 VLAN ID 和“any”作为输入列表。请注意,此选项仅对子接口有效,在为接口配置时无效。 |
|
此选项仅与 state *parsed* 一起使用。 此选项的值应为通过执行命令 **show running-config interface** 从 IOS-XR 设备接收到的输出。 state *parsed* 从 |
|
模块完成后的配置状态 选项
|
备注
注意
此模块使用连接
network_cli
。请参见 IOS-XR 平台选项。
示例
# Using merged
#
# Before state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# !
- name: Merge provided configuration with device configuration
cisco.iosxr.iosxr_l2_interfaces:
config:
- name: GigabitEthernet0/0/0/3
native_vlan: 20
- name: GigabitEthernet0/0/0/4
native_vlan: 40
l2transport: true
l2protocol:
- stp: tunnel
- name: GigabitEthernet0/0/0/3.900
l2transport: true
q_vlan:
- 20
- 40
state: merged
# After state:
# ------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 10
# l2transport
# l2protocol stp tunnel
# !
# !
# interface GigabitEthernet0/0/0/3.900 l2transport
# dot1q vlan 20 40
# !
# Using replaced
#
# Before state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 10
# l2transport
# l2protocol stp tunnel
# !
# !
# interface GigabitEthernet0/0/0/3.900 l2transport
# dot1q vlan 20 40
# !
- name: >-
Replaces device configuration of listed interfaces with provided
configuration
cisco.iosxr.iosxr_l2_interfaces:
config:
- name: GigabitEthernet0/0/0/4
native_vlan: 40
l2transport: true
l2protocol:
- stp: forward
- name: GigabitEthernet0/0/0/3.900
q_vlan:
- 20
- any
state: replaced
# After state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 40
# l2transport
# l2protocol stp forward
# !
# !
# interface GigabitEthernet0/0/0/3.900 l2transport
# dot1q vlan 20 any
# !
# Using overridden
#
# Before state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 10
# l2transport
# l2protocol stp tunnel
# !
# !
# interface GigabitEthernet0/0/0/3.900 l2transport
# dot1q vlan 20 40
# !
- name: Override device configuration of all interfaces with provided configuration
cisco.iosxr.iosxr_l2_interfaces:
config:
- name: GigabitEthernet0/0/0/4
native_vlan: 40
l2transport: true
l2protocol:
- stp: forward
- name: GigabitEthernet0/0/0/3.900
q_vlan:
- 20
- any
state: overridden
# After state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 40
# l2transport
# l2protocol stp forward
# !
# !
# interface GigabitEthernet0/0/0/3.900
# dot1q vlan 20 any
# !
# Using deleted
#
# Before state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 10
# l2transport
# l2protocol stp tunnel
# !
# !
#
- name: "Delete L2 attributes of given interfaces (Note: This won't delete the interface itself)"
cisco.iosxr.iosxr_l2_interfaces:
config:
- name: GigabitEthernet0/0/0/4
state: deleted
# After state:
# ------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# !
# Using Deleted without any config passed
# "(NOTE: This will delete all of configured resource module attributes from each configured interface)"
#
# Before state:
# -------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# dot1q native vlan 20
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# dot1q native vlan 10
# l2transport
# l2protocol stp tunnel
# !
# !
- name: "Delete L2 attributes of all interfaces (Note: This won't delete the interface itself)"
cisco.iosxr.iosxr_l2_interfaces:
state: deleted
# After state:
# ------------
#
# viosxr#show running-config interface
# interface GigabitEthernet0/0/0/3
# description Ansible Network
# vrf custB
# ipv4 address 10.10.0.2 255.255.255.0
# duplex half
# shutdown
# !
# interface GigabitEthernet0/0/0/4
# description Test description
# !
# Using parsed
# parsed.cfg
# ------------
#
# interface Loopback888
# description test for ansible
# shutdown
# !
# interface MgmtEth0/0/CPU0/0
# ipv4 address 10.8.38.70 255.255.255.0
# !
# interface GigabitEthernet0/0/0/0
# description Configured and Merged by Ansible-Network
# mtu 110
# ipv4 address 172.31.1.1 255.255.255.0
# duplex half
# !
# interface GigabitEthernet0/0/0/1
# dot1q native vlan 10
# l2transport
# l2protocol cdp forward
# l2protocol pvst tunnel
# propagate remote-status
# !
# !
# interface GigabitEthernet0/0/0/3
# shutdown
# !
# interface GigabitEthernet0/0/0/3.900
# encapsulation dot1q 20 second-dot1q 40
# !
# interface GigabitEthernet0/0/0/4
# shutdown
# dot1q native vlan 40
# !
- name: Convert L2 interfaces config to argspec without connecting to the appliance
cisco.iosxr.iosxr_l2_interfaces:
running_config: "{{ lookup('file', './parsed.cfg') }}"
state: parsed
# Task Output (redacted)
# -----------------------
# "parsed": [
# {
# "name": "GigabitEthernet0/0/0/0"
# },
# {
# "l2protocol": [
# {
# "cdp": "forward"
# },
# {
# "pvst": "tunnel"
# }
# ],
# "l2transport": true,
# "name": "GigabitEthernet0/0/0/1",
# "native_vlan": 10,
# "propagate": true
# },
# {
# "name": "GigabitEthernet0/0/0/3"
# },
# {
# "name": "GigabitEthernet0/0/0/3.900",
# "q_vlan": [
# 20,
# 40
# ]
# },
# {
# "name": "GigabitEthernet0/0/0/4",
# "native_vlan": 40
# }
# ]
# Using rendered
- name: Render platform specific commands from task input using rendered state
cisco.iosxr.iosxr_l2_interfaces:
config:
- name: GigabitEthernet0/0/0/1
native_vlan: 10
l2transport: true
l2protocol:
- pvst: tunnel
- cdp: forward
propagate: true
- name: GigabitEthernet0/0/0/3.900
q_vlan:
- 20
- 40
- name: GigabitEthernet0/0/0/4
native_vlan: 40
state: rendered
# Task Output (redacted)
# -----------------------
# "rendered": [
# "interface GigabitEthernet0/0/0/1",
# "dot1q native vlan 10",
# "l2transport l2protocol pvst tunnel",
# "l2transport l2protocol cdp forward",
# "l2transport propagate remote-status",
# "interface GigabitEthernet0/0/0/3.900",
# "dot1q vlan 20 40",
# "interface GigabitEthernet0/0/0/4",
# "dot1q native vlan 40"
# ]
# Using gathered
# Before state:
# ------------
#
# RP/0/0/CPU0:an-iosxr-02#show running-config interface
# interface Loopback888
# description test for ansible
# shutdown
# !
# interface MgmtEth0/0/CPU0/0
# ipv4 address 10.8.38.70 255.255.255.0
# !
# interface GigabitEthernet0/0/0/0
# description Configured and Merged by Ansible-Network
# mtu 110
# ipv4 address 172.31.1.1 255.255.255.0
# duplex half
# !
# interface GigabitEthernet0/0/0/1
# dot1q native vlan 10
# l2transport
# l2protocol cdp forward
# l2protocol pvst tunnel
# propagate remote-status
# !
# !
# interface GigabitEthernet0/0/0/3
# shutdown
# !
# interface GigabitEthernet0/0/0/3.900
# encapsulation dot1q 20 second-dot1q 40
# !
# interface GigabitEthernet0/0/0/4
# shutdown
# dot1q native vlan 40
# !
- name: Gather IOSXR l2 interfaces as in given arguments
cisco.iosxr.iosxr_l2_interfaces:
config:
state: gathered
# Task Output (redacted)
# -----------------------
#
# "gathered": [
# {
# "name": "GigabitEthernet0/0/0/0"
# },
# {
# "l2protocol": [
# {
# "cdp": "forward"
# },
# {
# "pvst": "tunnel"
# }
# ],
# "l2transport": true,
# "name": "GigabitEthernet0/0/0/1",
# "native_vlan": 10,
# "propagate": true
# },
# {
# "name": "GigabitEthernet0/0/0/3"
# },
# {
# "name": "GigabitEthernet0/0/0/3.900",
# "q_vlan": [
# 20,
# 40
# ]
# },
# {
# "name": "GigabitEthernet0/0/0/4",
# "native_vlan": 40
# }
# ]
# After state:
# ------------
#
# RP/0/0/CPU0:an-iosxr-02#show running-config interface
# interface Loopback888
# description test for ansible
# shutdown
# !
# interface MgmtEth0/0/CPU0/0
# ipv4 address 10.8.38.70 255.255.255.0
# !
# interface GigabitEthernet0/0/0/0
# description Configured and Merged by Ansible-Network
# mtu 110
# ipv4 address 172.31.1.1 255.255.255.0
# duplex half
# !
# interface GigabitEthernet0/0/0/1
# dot1q native vlan 10
# l2transport
# l2protocol cdp forward
# l2protocol pvst tunnel
# propagate remote-status
# !
# !
# interface GigabitEthernet0/0/0/3
# shutdown
# !
# interface GigabitEthernet0/0/0/3.900
# encapsulation dot1q 20 second-dot1q 40
# !
# interface GigabitEthernet0/0/0/4
# shutdown
# dot1q native vlan 40
# !
返回值
常见的返回值在 此处 有记录,以下是此模块特有的字段
键 |
描述 |
---|---|
模块完成后的配置,以结构化数据形式呈现。 返回:发生更改时 示例: |
|
模块调用之前的配置,以结构化数据形式呈现。 返回:始终返回 示例: |
|
推送到远程设备的命令集 返回:始终返回 示例: |