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

config

list / elements=dictionary

A List of Layer-2 interface options

access

dictionary

Switchport mode access command to configure the interface as a Layer-2 access.

vlan

integer

Configure given VLAN in access port. It’s used as the access VLAN ID.

beacon

boolean

Disable/enable the beacon for an interface

Choices:

  • false

  • true

cdp_enable

boolean

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:

  • false

  • true

dictionary

Configure actions on link-flap

dictionary

Configure the port to error-disable on link-flap

integer

Configure the number of link-flaps to trigger the action

integer

Configure the interval to trigger the action

mode

aliases: switchport_mode

string

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:

  • "dot1q-tunnel"

  • "access"

  • "trunk"

  • "fex-fabric"

  • "fabricpath"

name

string / required

Full name of interface, i.e. Ethernet1/1.

spanning_tree

dictionary

added in cisco.nxos 13.1.0

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.

bpdufilter

boolean

BPDU filter of the interface, spanning-tree bpdufilter enable|disable.

true configures enable, false configures disable. When not set no line is configured and the global default applies.

Choices:

  • false

  • true

bpduguard

boolean

BPDU guard of the interface, spanning-tree bpduguard enable|disable.

true configures enable, false configures disable. When not set no line is configured and the global default applies.

Choices:

  • false

  • true

cost

integer

Spanning-tree path cost, spanning-tree cost <n>.

The range is enforced by the device.

The value is an integer. The device default spanning-tree cost auto cannot be given as a value and a cost auto line on the device is ignored. Leave the option out with state replaced, overridden or deleted to return to the default.

guard

string

Spanning-tree guard, spanning-tree guard loop|root|none.

Choices:

  • "loop"

  • "root"

  • "none"

string

Spanning-tree link type, spanning-tree link-type auto|point-to-point|shared.

auto is the default, the device does not display it. It is treated like an unset link type.

Choices:

  • "auto"

  • "point_to_point"

  • "shared"

mst

list / elements=dictionary

Per MST instance cost and port priority, spanning-tree mst <instances> cost|port-priority <n>.

Only effective when the switch runs MST (spanning-tree mode mst).

cost

integer

Path cost for the instances, at least 1 (the device rejects 0).

instances

string / required

MST instance or list of instances, for example 0,2-4.

port_priority

integer

Port priority for the instances, a multiple of 32 from 0 to 224.

port_priority

integer

Spanning-tree port priority, spanning-tree port-priority <n>.

Must be a multiple of 32 from 0 to 224, other values are rejected before any command is sent.

128 is the default, the device does not display it. It is treated like an unset priority.

port_type

string

Spanning-tree port type, spanning-tree port type edge|edge trunk|network|normal.

Choices:

  • "edge"

  • "edge_trunk"

  • "network"

  • "normal"

vlans

list / elements=dictionary

Per VLAN cost and port priority, spanning-tree vlan <vlans> cost|port-priority <n>.

Only effective in the PVST modes (rapid-pvst or pvst).

cost

integer

Path cost for the VLANs.

port_priority

integer

Port priority for the VLANs, a multiple of 32 from 0 to 224.

vlans

string / required

VLAN or list of VLANs, for example 1,3-5.

storm_control

dictionary

added in cisco.nxos 13.1.0

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

string

Action taken when a storm is detected, storm-control action shutdown|trap.

Choices:

  • "shutdown"

  • "trap"

broadcast

dictionary

Broadcast storm-control, storm-control broadcast level <level>.

level

string

Suppression level in percent as a decimal string such as 0.01 or 1.00.

Compared as a number, 1.0 and 1.00 are the same level.

100.00 is the default, the device does not display it. It is treated like an unset level.

multicast

dictionary

Multicast storm-control, storm-control multicast level <level>.

level

string

Suppression level in percent as a decimal string such as 0.01 or 1.00.

Compared as a number, 1.0 and 1.00 are the same level.

100.00 is the default, the device does not display it. It is treated like an unset level.

unicast

dictionary

Unicast storm-control, storm-control unicast level <level>.

level

string

Suppression level in percent as a decimal string such as 0.01 or 1.00.

Compared as a number, 1.0 and 1.00 are the same level.

100.00 is the default, the device does not display it. It is treated like an unset level.

trunk

dictionary

Switchport mode trunk command to configure the interface as a Layer-2 trunk.

allowed_vlans

string

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.

allowed_vlans_implicit

boolean

Read-only flag set by the module in gathered/parsed facts when a trunk interface has no explicit switchport trunk allowed vlan line and the module synthesizes the default 1-4094 range.

When this flag is present in the current device state and state=merged is used, the module generates a SET command instead of ADD, allowing users to restrict default trunks to specific VLANs without switching to state=replaced.

This option should not be set in playbook config; it is informational only.

Choices:

  • false

  • true

allowed_vlans_none

boolean

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:

  • false

  • true

native_vlan

integer

Native VLAN to be configured in trunk port. It is used as the trunk native VLAN ID.

running_config

string

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 running_config option and transforms it into Ansible structured data as per the resource module’s argspec and the value is then returned in the parsed key within the result.

state

string

The state of the configuration after module completion.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

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_tree port_type (edge and edge_trunk), bpduguard (true), guard (root), cost, port_priority, link_type (point_to_point) and storm_control level of broadcast, multicast and unicast.

  • The other spanning_tree and storm_control values 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 default and spanning-tree loopguard default change 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_type normal, bpduguard false, bpdufilter false, guard none) are managed as explicit lines.

  • spanning_tree and storm_control apply 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 a switchport line or no no switchport line while system default switchport is configured. To know the default the module runs show 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_tree and storm_control settings of every interface that is not listed.

  • state=replaced and state=overridden send no cdp enable unless cdp_enable=true is listed for the interface (existing behaviour).

  • Configure spanning_tree and storm_control on the port-channel, not on its member ports.

  • On a vPC port-channel the spanning_tree settings must be identical on both vPC peers. A mismatch makes the vPC type-1 inconsistent until the settings are aligned.

  • storm-control multi commands are not supported.

  • The mst and vlans options of spanning_tree are 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 the vlans values 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_tree mst; cost and port priority were applied to a port-channel and shown by show 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

after

list / elements=string

The configuration as structured data after module completion.

Returned: when changed

Sample: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

before

list / elements=string

The configuration as structured data prior to module invocation.

Returned: always

Sample: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

commands

list / elements=string

The set of commands pushed to the remote device.

Returned: always

Sample: ["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,6,7,8,9,10,15", "switchport trunk native vlan 20"]

gathered

list / elements=string

Facts about the network resource gathered from the remote device as structured data.

Returned: when state is gathered

Sample: ["This output will always be in the same format as the module argspec.\n"]

parsed

list / elements=string

The device native config provided in running_config option parsed into structured data as per module argspec.

Returned: when state is parsed

Sample: ["This output will always be in the same format as the module argspec.\n"]

Authors

  • Trishna Guha (@trishnaguha)

  • Vinay Mulugund (@roverflow)