cisco.ios.ios_monitor_sessions module – Resource module to configure SPAN monitor sessions.
Note
This module is part of the cisco.ios collection (version 11.7.1).
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.ios.
To use it in a playbook, specify: cisco.ios.ios_monitor_sessions.
New in cisco.ios 11.7.0
Synopsis
This module provides declarative management of SPAN (Switched Port Analyzer) monitor sessions on Cisco IOS-XE devices.
Local SPAN (source interface to destination interface) is supported on Catalyst switches.
ERSPAN source sessions are supported on IOS-XE routers such as C8000V, where local SPAN is rejected (NGIO switch only).
VLAN-based sources and RSPAN are not covered by this module.
Aliases: monitor_sessions
Parameters
Parameter |
Comments |
|---|---|
List of monitor session configurations. |
|
Destination configuration (local SPAN interface or ERSPAN). |
|
Replicate the encapsulation of the monitored traffic. Choices:
|
|
ERSPAN ID for |
|
Destination interface name for local SPAN. |
|
ERSPAN destination IP address. |
|
ERSPAN origin IP address. |
|
Monitor session number. |
|
Session type as configured on the device.
Choices:
|
|
List of source interface specifications. |
|
Traffic direction to monitor on the source interface.
Choices:
|
|
List of source interface names for this source entry. Each element is a single interface name (e.g. All interfaces in the list share the same |
|
This option is used only with state parsed. The value of this option should be the output of show running-config | section ^monitor session executed on the device. The state parsed reads the configuration from this option and transforms it into Ansible structured data as per the resource module’s argspec. |
|
The state the configuration should be left in. merged adds or updates monitor sessions without removing existing ones. replaced replaces source and destination configuration for the specified sessions, leaving unspecified sessions intact. overridden replaces the entire monitor session configuration; sessions not present in deleted removes the specified sessions, or all sessions when rendered generates CLI commands from gathered retrieves and returns the running configuration as structured data without modifying the device. parsed parses the configuration provided in Choices:
|
Notes
Note
Tested against Cisco IOS-XE on Cat9k switches (local SPAN) and C8000V (ERSPAN).
This module works with connection
network_cli.Interface names in
configmust match the abbreviated form used in the running configuration (e.g.Gi1/0/1,Gi2,Po2,Twe1/0/2).Local SPAN is not supported on IOS-XE routers without an NGIO switch module. Use
session_type=erspan-sourceon those platforms.
Examples
# Using state: merged
# Before state:
# -------------
# (no monitor session configuration)
- name: Configure SPAN session 1 with multiple sources and replicate encapsulation
cisco.ios.ios_monitor_sessions:
config:
- session: 1
sources:
- interfaces:
- Twe1/0/2
- Twe1/0/12
- Twe1/0/45
- interfaces:
- Po2
destination:
interface: Po3
encapsulation_replicate: true
state: merged
# Commands fired:
# ---------------
# monitor session 1 source interface Twe1/0/2 , Twe1/0/12 , Twe1/0/45 , Po2
# monitor session 1 destination interface Po3 encapsulation replicate
# After state:
# ------------
# monitor session 1 source interface Twe1/0/2 , Twe1/0/12 , Twe1/0/45
# monitor session 1 source interface Po2
# monitor session 1 destination interface Po3 encapsulation replicate
# Using state: merged (ERSPAN on IOS-XE routers)
- name: Configure ERSPAN source session on C8000V
cisco.ios.ios_monitor_sessions:
config:
- session: 1
session_type: erspan-source
sources:
- interfaces:
- Gi2
- Gi3
destination:
erspan_id: 10
ip_address: 192.0.2.1
origin_ip_address: 192.0.2.2
state: merged
# Commands fired:
# ---------------
# monitor session 1 type erspan-source
# source interface Gi2 , Gi3
# monitor session 1 type erspan-source
# destination
# erspan-id 10
# ip address 192.0.2.1
# origin ip address 192.0.2.2
# Using state: merged with direction
# Before state:
# -------------
# (no monitor session configuration)
- name: Configure SPAN session with rx-only sources
cisco.ios.ios_monitor_sessions:
config:
- session: 2
sources:
- interfaces:
- "Gi1/0/1 - 3"
direction: rx
- interfaces:
- Gi1/0/5
destination:
interface: Gi1/0/48
state: merged
# Commands fired:
# ---------------
# monitor session 2 source interface Gi1/0/1 , Gi1/0/2 , Gi1/0/3 rx
# monitor session 2 source interface Gi1/0/5
# monitor session 2 destination interface Gi1/0/48
# Using state: replaced
# Before state:
# -------------
# monitor session 1 source interface Twe1/0/2 , Twe1/0/12 , Twe1/0/45
# monitor session 1 source interface Po2
# monitor session 1 destination interface Po3 encapsulation replicate
- name: Replace session 1 with updated source list
cisco.ios.ios_monitor_sessions:
config:
- session: 1
sources:
- interfaces:
- Po2
- interfaces:
- Po4
destination:
interface: Po3
encapsulation_replicate: true
state: replaced
# Commands fired:
# ---------------
# no monitor session 1 source interface Twe1/0/2 , Twe1/0/12 , Twe1/0/45
# monitor session 1 source interface Po4
# After state:
# ------------
# monitor session 1 source interface Po2
# monitor session 1 source interface Po4
# monitor session 1 destination interface Po3 encapsulation replicate
# Using state: overridden
# Before state:
# -------------
# monitor session 1 source interface Po2
# monitor session 1 destination interface Po3 encapsulation replicate
# monitor session 2 source interface Gi1/0/1
# monitor session 2 destination interface Gi1/0/48
- name: Override all sessions - remove session 2 and update session 1
cisco.ios.ios_monitor_sessions:
config:
- session: 1
sources:
- interfaces:
- Po2
destination:
interface: Po3
encapsulation_replicate: true
state: overridden
# Commands fired:
# ---------------
# no monitor session 2
# Using state: deleted - specific session
- name: Delete monitor session 1
cisco.ios.ios_monitor_sessions:
config:
- session: 1
state: deleted
# Commands fired:
# ---------------
# no monitor session 1
# Using state: deleted - all sessions
- name: Delete all monitor sessions
cisco.ios.ios_monitor_sessions:
state: deleted
# Commands fired:
# ---------------
# no monitor session 1
# no monitor session 2
# Using state: gathered
- name: Gather monitor session facts
cisco.ios.ios_monitor_sessions:
state: gathered
# Returns:
# gathered:
# - session: 1
# sources:
# - interfaces:
# - Twe1/0/2
# - Twe1/0/12
# - Twe1/0/45
# direction: both
# - interfaces:
# - Po2
# direction: both
# destination:
# interface: Po3
# encapsulation_replicate: true
# Using state: rendered
- name: Render monitor session commands without connecting to the device
cisco.ios.ios_monitor_sessions:
config:
- session: 1
sources:
- interfaces:
- Po2
destination:
interface: Po3
encapsulation_replicate: true
state: rendered
# Returns:
# rendered:
# - monitor session 1 source interface Po2
# - monitor session 1 destination interface Po3 encapsulation replicate
# Using state: parsed
- name: Parse monitor session configuration
cisco.ios.ios_monitor_sessions:
running_config: |
monitor session 1 source interface Twe1/0/2 , Twe1/0/12 , Twe1/0/45
monitor session 1 source interface Po2
monitor session 1 destination interface Po3 encapsulation replicate
state: parsed
# Returns:
# parsed:
# - session: 1
# sources:
# - interfaces:
# - Twe1/0/2
# - Twe1/0/12
# - Twe1/0/45
# direction: both
# - interfaces:
# - Po2
# direction: both
# destination:
# interface: Po3
# encapsulation_replicate: true
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
The resulting configuration module invocation. Returned: when changed Sample: |
|
The configuration prior to the module invocation. Returned: always Sample: |
|
The set of commands pushed to the remote device. Returned: when state is 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: |
|
The set of CLI commands generated from the value of config option. Returned: when state is Sample: |