cisco.nxos.nxos_l2_interfaces module – L2 interfaces resource module.
Note
This module is part of the cisco.nxos collection (version 14.0.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install cisco.nxos.
To use it in a playbook, specify: cisco.nxos.nxos_l2_interfaces.
New in cisco.nxos 1.0.0
Synopsis
This module manages Layer-2 interfaces attributes of NX-OS Interfaces.
Note
This module has a corresponding action plugin.
Aliases: l2_interfaces
Parameters
Parameter |
Comments |
|---|---|
A List of Layer-2 interface options |
|
Switchport mode access command to configure the interface as a Layer-2 access. |
|
Configure given VLAN in access port. It’s used as the access VLAN ID. |
|
Disable/enable the beacon for an interface Choices:
|
|
Enable/disable CDP on the interface. For port-channel member interfaces, configure CDP on the port-channel interface as Ansible does not support configuring CDP directly on port-channel member interfaces. Choices:
|
|
Configure actions on link-flap |
|
Configure the port to error-disable on link-flap |
|
Configure the number of link-flaps to trigger the action |
|
Configure the interval to trigger the action |
|
Mode in which interface needs to be configured. Access mode is not shown in interface facts, so idempotency will not be maintained for switchport mode access and every time the output will come as changed=True. Choices:
|
|
Full name of interface, i.e. Ethernet1/1. |
|
Spanning-tree settings of the interface. Only the explicit interface lines are managed, values left out are removed with state=replaced, state=overridden and state=deleted. |
|
BPDU filter of the interface,
Choices:
|
|
BPDU guard of the interface,
Choices:
|
|
Spanning-tree path cost, The range is enforced by the device. The value is an integer. The device default |
|
Spanning-tree guard, Choices:
|
|
Spanning-tree link type,
Choices:
|
|
Per MST instance cost and port priority, Only effective when the switch runs MST ( |
|
Path cost for the instances, at least 1 (the device rejects 0). |
|
MST instance or list of instances, for example |
|
Port priority for the instances, a multiple of 32 from 0 to 224. |
|
Spanning-tree port priority, Must be a multiple of 32 from 0 to 224, other values are rejected before any command is sent.
|
|
Spanning-tree port type, Choices:
|
|
Per VLAN cost and port priority, Only effective in the PVST modes ( |
|
Path cost for the VLANs. |
|
Port priority for the VLANs, a multiple of 32 from 0 to 224. |
|
VLAN or list of VLANs, for example |
|
Storm-control settings of the interface. Only the explicit interface lines are managed, values left out are removed with state=replaced, state=overridden and state=deleted. |
|
Action taken when a storm is detected, Choices:
|
|
Broadcast storm-control, |
|
Suppression level in percent as a decimal string such as Compared as a number,
|
|
Multicast storm-control, |
|
Suppression level in percent as a decimal string such as Compared as a number,
|
|
Unicast storm-control, |
|
Suppression level in percent as a decimal string such as Compared as a number,
|
|
Switchport mode trunk command to configure the interface as a Layer-2 trunk. |
|
List of allowed VLANs in a given trunk port. These are the only VLANs that will be configured on the trunk. The module would consider 1-4093 as the default range enabled if switchport mode is trunk. |
|
Read-only flag set by the module in gathered/parsed facts when a trunk interface has no explicit When this flag is present in the current device state and This option should not be set in playbook config; it is informational only. Choices:
|
|
This option governs the `switchport trunk allowed vlan none` configuration negation of this command would consider 1-4093 as the default. This attribute does not ensure idempotency. Choices:
|
|
Native VLAN to be configured in trunk port. It is used as the trunk native VLAN ID. |
|
This option is used only with state parsed. The value of this option should be the output received from the NX-OS device by executing the command show running-config | section ^interface. The state parsed reads the configuration from |
|
The state of the configuration after module completion. Choices:
|
Notes
Note
Tested against NXOS 10.3(2) on CML
Unsupported for Cisco MDS
Tested against NX-OS 10.6(4) on N9K-C93180YC-FX for
spanning_treeport_type(edgeandedge_trunk),bpduguard(true),guard(root),cost,port_priority,link_type(point_to_point) andstorm_controllevelofbroadcast,multicastandunicast.The other
spanning_treeandstorm_controlvalues are generated from the documented NX-OS command syntax but were not verified on a device.Only explicit interface lines are managed. Global settings such as
spanning-tree port type edge default,spanning-tree bpduguard defaultandspanning-tree loopguard defaultchange the effective behaviour of a port but are not interface configuration and are neither read nor changed by this module.Values that the device accepts but never displays (
spanning-tree link-type auto,spanning-tree port-priority 128,storm-control <type> level 100.00) are treated like unset values, listing them removes a different configured value. Values that are displayed (port_typenormal,bpduguardfalse,bpdufilterfalse,guardnone) are managed as explicit lines.spanning_treeandstorm_controlapply to switchports and port-channels. The interface commands do not exist on a routed port. When one of the options is used with state=merged, state=replaced or state=overridden the module fails before sending any command unless the interface is a confirmed switchport, that is it has aswitchportline or nono switchportline whilesystem default switchportis configured. To know the default the module runsshow running-config all | incl 'system default switchport'once. Routed ports are not reported in the facts.Interface level
storm-control <type> level pps <n>is not supported by this module because N9K-C93180YC-FX NX-OS 10.6(4) accepts it without storing it.state=overridden removes the
spanning_treeandstorm_controlsettings of every interface that is not listed.state=replaced and state=overridden send
no cdp enableunlesscdp_enable=trueis listed for the interface (existing behaviour).Configure
spanning_treeandstorm_controlon the port-channel, not on its member ports.On a vPC port-channel the
spanning_treesettings must be identical on both vPC peers. A mismatch makes the vPC type-1 inconsistent until the settings are aligned.storm-control multicommands are not supported.The
mstandvlansoptions ofspanning_treeare accepted, stored and removable in any spanning-tree mode, but they take effect only in MST and in the PVST modes respectively. In MST mode thevlansvalues are stored and shown in the running configuration and ignored by spanning tree.Tested against NX-OS 10.6(4) on N9K-C93180YC-FX in MST mode for
spanning_treemst; cost and port priority were applied to a port-channel and shown byshow spanning-tree mst.
Examples
# Using merged
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
# switchport trunk native vlan 20
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
- name: Merge provided configuration with device configuration
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
trunk:
native_vlan: 10
allowed_vlans: 2,4,15
- name: Ethernet1/2
access:
vlan: 30
state: merged
# Task Output
# -----------
#
# before:
# - name: Loopback999
# - name: Ethernet1/2
# - name: mgmt0
# - name: Ethernet1/1
# commands:
# - interface Ethernet1/1
# - switchport trunk allowed vlan 2,4,15
# - switchport trunk native vlan 10
# - interface Ethernet1/2
# - switchport access vlan 30
# after:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: 2,4,15
# native_vlan: 10
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# - name: Loopback999
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport trunk native vlan 10
# switchport trunk allowed vlans 2,4,15
# interface Ethernet1/2
# switchport access vlan 30
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
# Using merged to restrict default trunk VLANs
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/4
# switchport mode trunk
# switchport trunk native vlan 99
#
# Note: No explicit "switchport trunk allowed vlan" line means the
# interface allows all VLANs (1-4094) by default. The module detects
# this as implicit and sets allowed_vlans_implicit: true in facts.
- name: Restrict default trunk to specific VLANs using merged state
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/4
trunk:
allowed_vlans: "100,200"
state: merged
# Task Output
# -----------
#
# before:
# - name: Ethernet1/4
# mode: trunk
# trunk:
# allowed_vlans: "1-4094"
# allowed_vlans_implicit: true
# native_vlan: 99
# commands:
# - interface Ethernet1/4
# - switchport trunk allowed vlan 100,200
# after:
# - name: Ethernet1/4
# mode: trunk
# trunk:
# allowed_vlans: "100,200"
# native_vlan: 99
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/4
# switchport mode trunk
# switchport trunk native vlan 99
# switchport trunk allowed vlan 100,200
#
# Note: Because the have VLANs were implicit (default), merged used a
# SET command to restrict the trunk. If the trunk already had explicit
# VLANs, merged would use ADD to append only new VLANs.
# Using replaced
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport trunk native vlan 10
# switchport trunk allowed vlans 2,4,15
# interface Ethernet1/2
# switchport access vlan 30
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
- name: Replace device configuration of specified L2 interfaces with provided configuration.
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
trunk:
native_vlan: 20
allowed_vlans: 5-10, 15
state: replaced
# Task Output
# -----------
#
# before:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: 2,4,15
# native_vlan: 10
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# commands:
# - interface Ethernet1/1
# - no switchport trunk native vlan
# - switchport trunk allowed vlan 5-10,15
# - switchport trunk native vlan 20
# after:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: 5-10,15
# native_vlan: 20
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport trunk native vlan 20
# switchport trunk allowed vlan 5-10,15
# interface Ethernet1/2
# switchport trunk native vlan 20
# switchport mode trunk
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
# Using overridden
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport trunk native vlan 20
# switchport trunk allowed vlan 5-10,15
# interface Ethernet1/2
# switchport trunk native vlan 20
# switchport mode trunk
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
- name: Override device configuration with provided configuration.
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/2
access:
vlan: 30
state: overridden
# Task Output
# -----------
#
# before:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: 5,6,7,8,9,10,15
# native_vlan: 20
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# commands:
# - interface Ethernet1/1
# - no switchport trunk allowed vlan
# - no switchport trunk native vlan
# after:
# - name: Ethernet1/1
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
# switchport access vlan 30
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
# Using deleted
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport trunk native vlan 10
# switchport trunk allowed vlan 2,4,15
# interface Ethernet1/2
# switchport access vlan 30
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
- name: Delete L2 attributes of given interfaces (Note This won't delete the interface
itself).
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
- name: Ethernet1/2
state: deleted
# Task Output
# -----------
#
# before:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: 2,4,15
# native_vlan: 10
# - access:
# vlan: 30
# name: Ethernet1/2
# - name: mgmt0
# commands:
# - interface Ethernet1/1
# - no switchport trunk allowed vlan
# - no switchport trunk native vlan
# - interface Ethernet1/2
# - no switchport access vlan
# after:
# - name: Ethernet1/1
# - name: Ethernet1/2
# - name: mgmt0
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
# interface mgmt0
# ip address dhcp
# ipv6 address auto-config
# Using rendered
- name: Render platform specific configuration lines (without connecting to the device)
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
trunk:
native_vlan: 10
allowed_vlans: 2,4,15
- name: Ethernet1/2
access:
vlan: 30
- name: Ethernet1/3
trunk:
native_vlan: 20
allowed_vlans: 5-10, 15
state: rendered
# Task Output
# -----------
#
# rendered:
# - interface Ethernet1/1
# - switchport trunk allowed vlan 2,4,15
# - switchport trunk native vlan 10
# - interface Ethernet1/2
# - switchport access vlan 30
# - interface Ethernet1/3
# - switchport trunk allowed vlan 5-10,15
# - switchport trunk native vlan 20
# Using parsed
# parsed.cfg
# ------------
#
# interface Ethernet1/800
# switchport access vlan 18
# switchport trunk allowed vlan 210
# interface Ethernet1/801
# switchport trunk allowed vlan 2,4,15
- name: Use parsed state to convert externally supplied config to structured format
cisco.nxos.nxos_l2_interfaces:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task output
# -----------
#
# parsed:
# - name: Ethernet1/800
# access:
# vlan: 18
# trunk:
# allowed_vlans: "210"
# - name: Ethernet1/801
# trunk:
# allowed_vlans: "2,4,15"
# Using gathered
# Before state:
# -------------
#
# switch# sh running-config | section ^interface
# interface Ethernet1/1
# switchport access vlan 6
# switchport trunk allowed vlan 200
# interface Ethernet1/2
# switchport trunk native vlan 10
- name: Gather l2_interfaces facts from the device using nxos_l2_interfaces
cisco.nxos.nxos_l2_interfaces:
state: gathered
# Task output
# -----------
#
# gathered:
# - name: "Ethernet1/1"
# access:
# vlan: 6
# trunk:
# allowed_vlans: "200"
# - name: "Ethernet1/2"
# trunk:
# native_vlan: 10
# Using allowed_vlans_none
# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport mode trunk
# switchport trunk allowed vlan 10-100
# interface Ethernet1/2
# switchport mode trunk
- name: Configure trunk interface to allow no VLANs (block all traffic)
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
trunk:
allowed_vlans_none: true
state: merged
# Task Output
# -----------
#
# before:
# - name: Ethernet1/1
# trunk:
# allowed_vlans: "10-100"
# - name: Ethernet1/2
# trunk:
# allowed_vlans: "1-4094"
# commands:
# - interface Ethernet1/1
# - switchport trunk allowed vlan none
# after:
# - name: Ethernet1/1
# trunk:
# allowed_vlans_none: true
# - name: Ethernet1/2
# trunk:
# allowed_vlans: "1-4094"
# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# switchport mode trunk
# switchport trunk allowed vlan none
# interface Ethernet1/2
# switchport mode trunk
# Note: When allowed_vlans_none is not configured on a trunk interface,
# the module assumes the default allowed VLANs range of 1-4094.
# This is consistent with NX-OS default behavior where all VLANs are
# allowed on trunk ports unless explicitly restricted.
- name: Configure specific VLANs after removing none restriction
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/1
trunk:
allowed_vlans: "10,20,30"
- name: Ethernet1/2
trunk:
allowed_vlans_none: true
state: replaced
# Task Output
# -----------
#
# commands:
# - interface Ethernet1/1
# - switchport trunk allowed vlan 10,20,30
# - interface Ethernet1/2
# - switchport trunk allowed vlan none
# Using merged with spanning_tree and storm_control
# Before state:
# -------------
#
# switch# show running-config | section ^interface
# interface Ethernet1/25
# switchport
# switchport mode trunk
# spanning-tree guard root
# interface port-channel20
# switchport
- name: Merge spanning-tree and storm-control settings
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/25
spanning_tree:
port_type: edge_trunk
bpduguard: true
cost: 100
storm_control:
broadcast:
level: "0.01"
multicast:
level: "10.50"
action: trap
- name: port-channel20
spanning_tree:
port_type: network
mst:
- instances: "0,2-4"
cost: 200
state: merged
# Task Output
# -----------
#
# commands:
# - interface Ethernet1/25
# - spanning-tree port type edge trunk
# - spanning-tree bpduguard enable
# - spanning-tree cost 100
# - storm-control broadcast level 0.01
# - storm-control multicast level 10.50
# - storm-control action trap
# - interface port-channel20
# - spanning-tree port type network
# - spanning-tree mst 0,2-4 cost 200
# After state:
# ------------
#
# switch# show running-config | section ^interface
# interface Ethernet1/25
# switchport
# switchport mode trunk
# spanning-tree cost 100
# spanning-tree port type edge trunk
# spanning-tree bpduguard enable
# spanning-tree guard root
# storm-control broadcast level 0.01
# storm-control multicast level 10.50
# storm-control action trap
# interface port-channel20
# switchport
# spanning-tree port type network
# spanning-tree mst 0,2-4 cost 200
# Using replaced with spanning_tree and storm_control
# Before state:
# -------------
#
# interface Ethernet1/25
# switchport
# switchport mode trunk
# spanning-tree cost 100
# spanning-tree port type edge trunk
# spanning-tree bpduguard enable
# spanning-tree guard root
# storm-control broadcast level 0.01
- name: Replace the settings of an interface, whatever is not listed is removed
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/25
mode: trunk
cdp_enable: true
spanning_tree:
port_type: edge_trunk
bpduguard: false
storm_control:
broadcast:
level: "1.0"
state: replaced
# Task Output
# -----------
#
# commands:
# - interface Ethernet1/25
# - spanning-tree bpduguard disable
# - no spanning-tree guard
# - no spanning-tree cost
# - storm-control broadcast level 1.00
# After state:
# ------------
#
# interface Ethernet1/25
# switchport
# switchport mode trunk
# spanning-tree port type edge trunk
# spanning-tree bpduguard disable
# storm-control broadcast level 1.00
# Using overridden with spanning_tree and storm_control
# Before state:
# -------------
#
# interface Ethernet1/25
# switchport
# spanning-tree port type edge
# interface Ethernet1/26
# switchport
# spanning-tree bpduguard enable
# storm-control unicast level 5.00
- name: Override the layer-2 configuration of all interfaces
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/25
cdp_enable: true
spanning_tree:
port_type: edge
state: overridden
# Task Output
# -----------
#
# commands:
# - interface Ethernet1/26
# - no spanning-tree bpduguard
# - no storm-control unicast level 5.00
# After state:
# ------------
#
# interface Ethernet1/25
# switchport
# spanning-tree port type edge
# interface Ethernet1/26
# switchport
# Using deleted with spanning_tree and storm_control
# Before state:
# -------------
#
# interface Ethernet1/25
# switchport
# spanning-tree port type edge trunk
# spanning-tree vlan 1,3-5 cost 10
# storm-control broadcast level 0.01
# storm-control action shutdown
- name: Remove the layer-2 configuration of an interface
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/25
state: deleted
# Task Output
# -----------
#
# commands:
# - interface Ethernet1/25
# - no spanning-tree port type edge trunk
# - no storm-control broadcast level 0.01
# - no storm-control action shutdown
# - no spanning-tree vlan 1,3-5 cost
# After state:
# ------------
#
# interface Ethernet1/25
# switchport
# Using rendered with spanning_tree and storm_control
- name: Render the commands for spanning-tree and storm-control
cisco.nxos.nxos_l2_interfaces:
config:
- name: Ethernet1/25
spanning_tree:
port_type: edge
link_type: point_to_point
vlans:
- vlans: "1,3-5"
port_priority: 64
storm_control:
unicast:
level: "5"
state: rendered
# Task Output
# -----------
#
# rendered:
# - interface Ethernet1/25
# - spanning-tree port type edge
# - spanning-tree link-type point-to-point
# - storm-control unicast level 5.00
# - spanning-tree vlan 1,3-5 port-priority 64
# Using gathered with spanning_tree and storm_control
# Before state:
# -------------
#
# interface Ethernet1/25
# switchport
# switchport mode trunk
# spanning-tree port-priority 64
# spanning-tree port type edge trunk
# spanning-tree bpduguard enable
# storm-control broadcast level 0.01
# storm-control multicast level 1.00
- name: Gather spanning-tree and storm-control settings
cisco.nxos.nxos_l2_interfaces:
state: gathered
# Task Output
# -----------
#
# gathered:
# - name: Ethernet1/25
# mode: trunk
# spanning_tree:
# bpduguard: true
# port_priority: 64
# port_type: edge_trunk
# storm_control:
# broadcast:
# level: "0.01"
# multicast:
# level: "1.00"
# Using parsed with spanning_tree and storm_control
# File: parsed.cfg
# ----------------
#
# interface port-channel20
# spanning-tree port type network
# spanning-tree bpduguard disable
# spanning-tree mst 0,2-4 cost 200
# storm-control broadcast level 50.50
- name: Parse the provided configuration
cisco.nxos.nxos_l2_interfaces:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task Output
# -----------
#
# parsed:
# - name: port-channel20
# spanning_tree:
# bpduguard: false
# mst:
# - cost: 200
# instances: 0,2-4
# port_type: network
# storm_control:
# broadcast:
# level: "50.50"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
The configuration as structured data after module completion. Returned: when changed Sample: |
|
The configuration as structured data prior to module invocation. Returned: always Sample: |
|
The set of commands pushed to the remote device. Returned: always Sample: |
|
Facts about the network resource gathered from the remote device as structured data. Returned: when state is Sample: |
|
The device native config provided in running_config option parsed into structured data as per module argspec. Returned: when state is Sample: |