cisco.ios.ios_l2_interfaces 模块 – 配置 L2 接口的资源模块。
注意
此模块是 cisco.ios 集合 (版本 9.0.3) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install cisco.ios
。
要在 playbook 中使用它,请指定: cisco.ios.ios_l2_interfaces
。
cisco.ios 1.0.0 中的新增功能
概要
此模块提供对 Cisco IOS 设备上第 2 层接口的声明式管理。
参数
参数 |
注释 |
---|---|
第 2 层接口选项的字典 |
|
Switchport mode access 命令,用于将接口配置为第 2 层访问接口。 |
|
在访问端口中配置给定的 VLAN。用作访问 VLAN ID。 |
|
在接口处于访问模式时设置 VLAN。 |
|
需要配置接口的模式。 其 Trunk 封装为“Auto”的接口不能配置为“trunk”模式。 选项
|
|
接口的全名,不包括任何逻辑单元编号,例如 GigabitEthernet0/1。 |
|
Switchport mode trunk 命令,用于将接口配置为第 2 层 Trunk。注意,封装始终设置为 dot1q。 |
|
给定 Trunk 端口中允许的 VLAN 列表。这些是将在 Trunk 上配置的唯一 VLAN。 |
|
接口处于 Trunk 模式时的 Trunk 封装。 选项
|
|
要在 Trunk 端口中配置的原生 VLAN。用作 Trunk 原生 VLAN ID。 |
|
要在 Trunk 端口中配置的修剪 VLAN。用作 Trunk 修剪 VLAN ID。 |
|
Switchport mode voice 命令,用于配置带有语音 VLAN 的接口。 |
|
在访问端口上配置给定的语音 VLAN。用作语音 VLAN ID。 |
|
在接口处于访问模式时设置 VLAN。 |
|
设置 VLAN 标记。dot1p(PVID 上的优先级标记)none(不告诉电话语音 VLAN)untagged(PVID 上未标记) 选项
|
|
此选项仅与状态 *parsed* 一起使用。 此选项的值应为通过执行命令 **show running-config | section ^interface** 从 IOS 设备接收到的输出。 状态 *parsed* 从 |
|
配置应保留的状态 状态 *rendered*、*gathered* 和 *parsed* 不会对设备进行任何更改。 状态 *rendered* 将 状态 *gathered* 将从设备获取运行配置,并将其转换为根据资源模块 argspec 的格式进行结构化数据,并在结果中的 *gathered* 键中返回该值。 状态 *parsed* 从 选项
|
注释
注意
已在 CML 上针对 Cisco IOSv 版本 15.2 进行测试。
此模块与连接
network_cli
一起使用。请参阅 https://docs.ansible.org.cn/ansible/latest/network/user_guide/platform_ios.html模块示例使用回调插件 (stdout_callback = yaml) 以 yaml 格式生成任务输出。
示例
# Using merged
# Before state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# media-type rj45
# negotiation auto
- name: Merge provided configuration with device configuration
cisco.ios.ios_l2_interfaces:
config:
- name: GigabitEthernet0/1
mode: access
access:
vlan: 10
voice:
vlan: 40
- name: GigabitEthernet0/2
mode: trunk
trunk:
allowed_vlans: 10-20,40
native_vlan: 20
pruning_vlans: 10,20
encapsulation: dot1q
state: merged
# Task Output
# -----------
#
# before:
# - name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# commands:
# - interface GigabitEthernet0/1
# - switchport access vlan 10
# - switchport voice vlan 40
# - switchport mode access
# - interface GigabitEthernet0/2
# - switchport mode trunk
# - switchport trunk encapsulation dot1q
# - switchport trunk native vlan 20
# - switchport trunk allowed vlan 10-20,40
# - switchport trunk pruning vlan 10,20
# after:
# - access:
# vlan: 10
# mode: access
# name: GigabitEthernet0/1
# voice:
# vlan: 40
# - mode: trunk
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 10-20
# - '40'
# encapsulation: dot1q
# native_vlan: 20
# pruning_vlans:
# - '10'
# - '20'
# After state:
# ------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 10
# switchport voice vlan 40
# switchport mode access
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport trunk allowed vlan 10-20,40
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 20
# switchport trunk pruning vlan 10,20
# switchport mode trunk
# media-type rj45
# negotiation auto
# Using replaced
# Before state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# media-type rj45
# negotiation auto
- name: Replaces device configuration with provided configuration
cisco.ios.ios_l2_interfaces:
config:
- name: GigabitEthernet0/2
trunk:
allowed_vlans: 20-25,40
native_vlan: 20
pruning_vlans: 10
encapsulation: isl
state: replaced
# Task Output
# -----------
#
# before:
# - name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# commands:
# - interface GigabitEthernet0/2
# - no switchport access vlan
# - switchport trunk encapsulation isl
# - switchport trunk native vlan 20
# - switchport trunk allowed vlan 20-25,40
# - switchport trunk pruning vlan 10
# after:
# - access:
# vlan: 20
# name: GigabitEthernet0/1
# - name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-25
# - '40'
# encapsulation: isl
# native_vlan: 20
# pruning_vlans:
# - '10'
# After state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport trunk allowed vlan 20-25,40
# switchport trunk encapsulation isl
# switchport trunk native vlan 20
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
# Using overridden
# Before state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 20
# media-type rj45
# negotiation auto
- name: Override device configuration of all l2 interfaces with provided configuration
cisco.ios.ios_l2_interfaces:
config:
- name: GigabitEthernet0/2
access:
vlan: 20
voice:
vlan: 40
state: overridden
# Task Output
# -----------
#
# before:
# - name: GigabitEthernet0/1
# trunk:
# encapsulation: dot1q
# native_vlan: 20
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# encapsulation: dot1q
# native_vlan: 20
# commands:
# - interface GigabitEthernet0/1
# - no switchport trunk encapsulation
# - no switchport trunk native vlan
# - interface GigabitEthernet0/2
# - switchport voice vlan 40
# - no switchport trunk encapsulation
# - no switchport trunk native vlan
# after:
# - name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# voice:
# vlan: 40
# After state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport voice vlan 40
# media-type rj45
# negotiation auto
# Using deleted
# Before state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk allowed vlan 20-40,60,80
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 10
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
- name: Delete IOS L2 interfaces as in given arguments
cisco.ios.ios_l2_interfaces:
config:
- name: GigabitEthernet0/1
state: deleted
# Task Output
# -----------
#
# before:
# - access:
# vlan: 20
# name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-40
# - '60'
# - '80'
# encapsulation: dot1q
# native_vlan: 10
# pruning_vlans:
# - '10'
# commands:
# - interface GigabitEthernet0/1
# - no switchport access vlan
# after:
# - name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-40
# - '60'
# - '80'
# encapsulation: dot1q
# native_vlan: 10
# pruning_vlans:
# - '10'
# After state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk allowed vlan 20-40,60,80
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 10
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
# Using deleted without config - delete all configuration
# Before state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk allowed vlan 20-40,60,80
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 10
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
- name: Delete IOS L2 interfaces as in given arguments
cisco.ios.ios_l2_interfaces:
state: deleted
# Task Output
# -----------
#
# before:
# - access:
# vlan: 20
# name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-40
# - '60'
# - '80'
# encapsulation: dot1q
# native_vlan: 10
# pruning_vlans:
# - '10'
# commands:
# - interface GigabitEthernet0/1
# - no switchport access vlan
# - interface GigabitEthernet0/2
# - no switchport access vlan
# - no switchport trunk encapsulation
# - no switchport trunk native vlan
# - no switchport trunk allowed vlan
# - no switchport trunk pruning vlan
# after:
# - name: GigabitEthernet0/1
# - name: GigabitEthernet0/2
# After state:
# -------------
#
# viosl2#show running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# media-type rj45
# negotiation auto
# Using gathered
# Before state:
# -------------
#
# vios#sh running-config | section ^interface
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk allowed vlan 20-40,60,80
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 10
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
- name: Gather facts for l2 interfaces
cisco.ios.ios_l2_interfaces:
config:
state: gathered
# Task Output
# -----------
#
# gathered:
# - access:
# vlan: 20
# name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-40
# - '60'
# - '80'
# encapsulation: dot1q
# native_vlan: 10
# pruning_vlans:
# - '10'
# Using rendered
- name: Render the commands for provided configuration
cisco.ios.ios_l2_interfaces:
config:
- name: GigabitEthernet0/1
access:
vlan: 30
- name: GigabitEthernet0/2
trunk:
allowed_vlans: 10-20,40
native_vlan: 20
pruning_vlans: 10,20
encapsulation: dot1q
state: rendered
# Task Output
# -----------
#
# rendered:
# - interface GigabitEthernet0/1
# - switchport access vlan 30
# - interface GigabitEthernet0/2
# - switchport trunk encapsulation dot1q
# - switchport trunk native vlan 20
# - switchport trunk allowed vlan 10-20,40
# - switchport trunk pruning vlan 10,20
# Using Parsed
# File: parsed.cfg
# ----------------
#
# interface GigabitEthernet0/1
# description Configured by Ansible
# switchport access vlan 20
# negotiation auto
# interface GigabitEthernet0/2
# description This is test
# switchport access vlan 20
# switchport trunk allowed vlan 20-40,60,80
# switchport trunk encapsulation dot1q
# switchport trunk native vlan 10
# switchport trunk pruning vlan 10
# media-type rj45
# negotiation auto
- name: Parse the commands for provided configuration
cisco.ios.ios_l2_interfaces:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task Output
# -----------
#
# parsed:
# - access:
# vlan: 20
# name: GigabitEthernet0/1
# - access:
# vlan: 20
# name: GigabitEthernet0/2
# trunk:
# allowed_vlans:
# - 20-40
# - '60'
# - '80'
# encapsulation: dot1q
# native_vlan: 10
# pruning_vlans:
# - '10'
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
键 |
描述 |
---|---|
模块执行后的最终配置。 返回:发生更改时 示例: |
|
模块执行前的配置。 返回:当 state 为 示例: |
|
推送到远程设备的命令集。 返回:当 state 为 示例: |
|
从远程设备收集到的关于网络资源的结构化数据事实。 返回:当 state 为 示例: |
|
根据模块 argspec 将 running_config 选项中提供的设备原生配置解析为结构化数据。 返回:当 state 为 示例: |
|
以设备原生格式呈现的任务中提供的配置(离线)。 返回:当 state 为 示例: |