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

config

list / elements=dictionary

List of monitor session configurations.

destination

dictionary

Destination configuration (local SPAN interface or ERSPAN).

encapsulation_replicate

boolean

Replicate the encapsulation of the monitored traffic.

Choices:

  • false ← (default)

  • true

erspan_id

integer

ERSPAN ID for session_type=erspan-source.

interface

string

Destination interface name for local SPAN.

ip_address

string

ERSPAN destination IP address.

origin_ip_address

string

ERSPAN origin IP address.

session

integer / required

Monitor session number.

session_type

string

Session type as configured on the device.

local is the Catalyst one-line SPAN syntax.

erspan-source is required on IOS-XE routers (C8000V, ISR, C8300) that reject local SPAN.

Choices:

  • "local"

  • "erspan-source"

sources

list / elements=dictionary

List of source interface specifications.

direction

string

Traffic direction to monitor on the source interface.

both is the default when no direction is specified.

Choices:

  • "rx"

  • "tx"

  • "both" ← (default)

interfaces

list / elements=string / required

List of source interface names for this source entry.

Each element is a single interface name (e.g. Gi1/0/1, Po2) or a range string exactly as it appears in the running configuration (e.g. Gi1/0/1 - 3).

All interfaces in the list share the same direction.

running_config

string

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.

state

string

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 config are removed.

deleted removes the specified sessions, or all sessions when config is omitted.

rendered generates CLI commands from config without connecting to the device.

gathered retrieves and returns the running configuration as structured data without modifying the device.

parsed parses the configuration provided in running_config and returns structured data.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "gathered"

  • "parsed"

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 config must 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-source on 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

after

list / elements=string

The resulting configuration module invocation.

Returned: when changed

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

before

list / elements=string

The configuration prior to the module invocation.

Returned: always

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

commands

list / elements=string

The set of commands pushed to the remote device.

Returned: when state is merged, replaced, overridden, or deleted

Sample: ["monitor session 1 source interface Po2", "monitor session 1 destination interface Po3 encapsulation replicate"]

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"]

rendered

list / elements=string

The set of CLI commands generated from the value of config option.

Returned: when state is rendered

Sample: ["monitor session 1 source interface Po2", "monitor session 1 destination interface Po3 encapsulation replicate"]

Authors

  • Jørgen Spange (@jorgenspange)