cisco.ios.ios_flow_monitor_global module – Resource module to configure Flexible NetFlow on Cisco IOS XE.

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_flow_monitor_global.

New in cisco.ios 11.7.0

Synopsis

  • This module manages the Flexible NetFlow global configuration on Cisco IOS XE devices.

  • It manages flow records, flow exporters, samplers, and flow monitors as named entities.

Aliases: flow_monitor_global

Parameters

Parameter

Comments

config

dictionary

Flexible NetFlow global configuration.

exporters

list / elements=dictionary

Flow exporter definitions.

description

string

Human-readable description of the exporter.

destination

string

Destination IP address for the exporter.

dscp

integer

DSCP value for exported packets.

export_protocol

string

Export protocol (ipfix or netflow-v9).

Choices:

  • "ipfix"

  • "netflow-v9"

name

string / required

Name of the flow exporter.

options

dictionary

Exporter option records to send.

application_table_timeout

integer

Timeout for application-table option export (seconds, NBAR).

exporter_stats_timeout

integer

Timeout for exporter-stats option export (seconds).

interface_table_timeout

integer

Timeout for interface-table option export (seconds).

sampler_table_timeout

integer

Timeout for sampler-table option export (seconds).

template_data_timeout

integer

Timeout for template data option export (seconds).

vrf_table_timeout

integer

Timeout for vrf-table option export (seconds).

source

string

Source interface for exported packets.

template_data_timeout

integer

Interval to re-send template records (seconds).

transport

dictionary

Transport protocol and port.

port

integer

Destination port number.

protocol

string

Transport protocol (tcp is router-only).

Choices:

  • "udp" ← (default)

  • "tcp"

ttl

integer

Time-to-live for exported packets.

vrf

string

VRF for the destination.

monitors

list / elements=dictionary

Flow monitor definitions.

cache

dictionary

Cache settings.

entries

integer

Maximum number of cache entries.

Catalyst 9300 accepts this without an error but does not keep it in the running configuration, so it is reported as changed on every run there.

timeout_active

integer

Active flow cache timeout (seconds).

timeout_inactive

integer

Inactive flow cache timeout (seconds).

timeout_update

integer

Update/sync cache timeout for permanent caches (seconds).

type

string

Cache type (permanent is router-only).

Choices:

  • "normal"

  • "permanent"

description

string

Human-readable description of the monitor.

exporters

list / elements=string

List of exporter names to use (supports multiple exporters).

name

string / required

Name of the flow monitor.

record

string

Name of the flow record to use.

records

list / elements=dictionary

Flow record definitions.

collect

dictionary

Flow record collect fields.

counter_bytes

boolean

Collect byte counter (collect counter bytes).

Accepted by Catalyst 9600 and routers. Rejected by Catalyst 9300 as an incomplete command, use counter_bytes_long or counter_bytes_layer2_long there.

Choices:

  • false

  • true

counter_bytes_layer2

boolean

Collect Layer 2 byte counter (collect counter bytes layer2).

Rejected by Catalyst 9300 and 9600 as an incomplete command, use counter_bytes_layer2_long there.

Choices:

  • false

  • true

counter_bytes_layer2_long

boolean

Collect 64-bit Layer 2 byte counter (collect counter bytes layer2 long).

This is the byte counter recommended for Catalyst 9300. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

counter_bytes_long

boolean

Collect 64-bit byte counter. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

counter_packets

boolean

Collect packet counter (collect counter packets).

Accepted by Catalyst 9600 and routers. Rejected by Catalyst 9300 as an incomplete command, use counter_packets_long there.

Choices:

  • false

  • true

counter_packets_long

boolean

Collect 64-bit packet counter. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

boolean

Collect ingress 802.1Q VLAN.

Choices:

  • false

  • true

boolean

Collect egress 802.1Q VLAN.

Choices:

  • false

  • true

boolean

Collect ingress destination MAC.

Choices:

  • false

  • true

boolean

Collect egress destination MAC.

Choices:

  • false

  • true

boolean

Collect ingress source MAC.

Choices:

  • false

  • true

boolean

Collect egress source MAC.

Choices:

  • false

  • true

flow_sampler

boolean

Collect flow sampler ID.

Choices:

  • false

  • true

interface_input

boolean

Collect input interface.

Choices:

  • false

  • true

interface_output

boolean

Collect output interface.

Choices:

  • false

  • true

ipv4_destination_address

boolean

Collect IPv4 destination address.

Choices:

  • false

  • true

ipv4_destination_mask

boolean

Collect IPv4 destination mask.

Choices:

  • false

  • true

ipv4_destination_prefix

boolean

Collect IPv4 destination prefix.

Choices:

  • false

  • true

ipv4_protocol

boolean

Collect IPv4 protocol.

Choices:

  • false

  • true

ipv4_source_address

boolean

Collect IPv4 source address.

Choices:

  • false

  • true

ipv4_source_mask

boolean

Collect IPv4 source mask.

Choices:

  • false

  • true

ipv4_source_prefix

boolean

Collect IPv4 source prefix.

Choices:

  • false

  • true

ipv4_version

boolean

Collect IPv4 version.

Choices:

  • false

  • true

ipv6_destination_address

boolean

Collect IPv6 destination address.

Choices:

  • false

  • true

ipv6_destination_mask

boolean

Collect IPv6 destination mask.

Choices:

  • false

  • true

ipv6_destination_prefix

boolean

Collect IPv6 destination prefix.

Choices:

  • false

  • true

ipv6_protocol

boolean

Collect IPv6 protocol.

Choices:

  • false

  • true

ipv6_source_address

boolean

Collect IPv6 source address.

Choices:

  • false

  • true

ipv6_source_mask

boolean

Collect IPv6 source mask.

Choices:

  • false

  • true

ipv6_source_prefix

boolean

Collect IPv6 source prefix.

Choices:

  • false

  • true

ipv6_version

boolean

Collect IPv6 version.

Choices:

  • false

  • true

routing_destination_as

boolean

Collect destination AS number (collect routing destination as).

Rejected by Catalyst 9300 and 9600 as an incomplete command, use routing_destination_as_4octet there.

Choices:

  • false

  • true

routing_destination_as_4octet

boolean

Collect 4-octet destination AS number. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

routing_destination_as_peer

boolean

Collect peer destination AS number.

Rejected by Catalyst 9300 and 9600 as an incomplete command.

Choices:

  • false

  • true

routing_next_hop_ipv4

boolean

Collect IPv4 next-hop address.

Choices:

  • false

  • true

routing_next_hop_ipv6

boolean

Collect IPv6 next-hop address.

Choices:

  • false

  • true

routing_source_as

boolean

Collect source AS number (collect routing source as).

Rejected by Catalyst 9300 and 9600 as an incomplete command, use routing_source_as_4octet there.

Choices:

  • false

  • true

routing_source_as_4octet

boolean

Collect 4-octet source AS number. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

routing_source_as_peer

boolean

Collect peer source AS number.

Rejected by Catalyst 9300 and 9600 as an incomplete command.

Choices:

  • false

  • true

timestamp_absolute_first

boolean

Collect absolute timestamp at flow start. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

timestamp_absolute_last

boolean

Collect absolute timestamp at last packet. Accepted on Catalyst 9300 and 9600.

Choices:

  • false

  • true

timestamp_sys_uptime_first

boolean

Collect system uptime at flow start.

Accepted by Catalyst 9600 and routers. Rejected by Catalyst 9300, use timestamp_absolute_first there.

Choices:

  • false

  • true

timestamp_sys_uptime_last

boolean

Collect system uptime at last packet.

Accepted by Catalyst 9600 and routers. Rejected by Catalyst 9300, use timestamp_absolute_last there.

Choices:

  • false

  • true

transport_destination_port

boolean

Collect transport destination port.

Choices:

  • false

  • true

transport_source_port

boolean

Collect transport source port.

Choices:

  • false

  • true

transport_tcp_flags

boolean

Collect TCP flags.

Choices:

  • false

  • true

match

dictionary

Flow record match fields.

application_name

boolean

Match application name (NBAR).

Choices:

  • false

  • true

boolean

Match 802.1Q priority.

Choices:

  • false

  • true

boolean

Match ingress 802.1Q VLAN.

Choices:

  • false

  • true

boolean

Match egress 802.1Q VLAN.

Choices:

  • false

  • true

boolean

Match EtherType.

Choices:

  • false

  • true

boolean

Match ingress destination MAC address.

Choices:

  • false

  • true

boolean

Match egress destination MAC address.

Choices:

  • false

  • true

boolean

Match ingress source MAC address.

Choices:

  • false

  • true

boolean

Match egress source MAC address.

Choices:

  • false

  • true

boolean

Match ingress VLAN.

Choices:

  • false

  • true

boolean

Match egress VLAN.

Choices:

  • false

  • true

flow_direction

boolean

Match flow direction (ingress/egress).

Choices:

  • false

  • true

interface_input

boolean

Match input interface.

Choices:

  • false

  • true

interface_output

boolean

Match output interface.

Choices:

  • false

  • true

ipv4_destination_address

boolean

Match IPv4 destination address.

Choices:

  • false

  • true

ipv4_protocol

boolean

Match IPv4 protocol field.

Choices:

  • false

  • true

ipv4_source_address

boolean

Match IPv4 source address.

Choices:

  • false

  • true

ipv4_tos

boolean

Match IPv4 ToS/DSCP field.

Choices:

  • false

  • true

ipv4_ttl

boolean

Match IPv4 TTL.

Choices:

  • false

  • true

ipv4_version

boolean

Match IPv4 version.

Choices:

  • false

  • true

ipv6_destination_address

boolean

Match IPv6 destination address.

Choices:

  • false

  • true

ipv6_hop_limit

boolean

Match IPv6 hop-limit.

Choices:

  • false

  • true

ipv6_protocol

boolean

Match IPv6 protocol.

Choices:

  • false

  • true

ipv6_source_address

boolean

Match IPv6 source address.

Choices:

  • false

  • true

ipv6_traffic_class

boolean

Match IPv6 traffic class.

Choices:

  • false

  • true

ipv6_version

boolean

Match IPv6 version.

Choices:

  • false

  • true

routing_vrf_input

boolean

Match input routing VRF.

Choices:

  • false

  • true

transport_destination_port

boolean

Match transport layer destination port.

Choices:

  • false

  • true

transport_icmp_ipv4_code

boolean

Match ICMP IPv4 code.

Choices:

  • false

  • true

transport_icmp_ipv4_type

boolean

Match ICMP IPv4 type.

Choices:

  • false

  • true

transport_icmp_ipv6_code

boolean

Match ICMP IPv6 code.

Choices:

  • false

  • true

transport_icmp_ipv6_type

boolean

Match ICMP IPv6 type.

Choices:

  • false

  • true

transport_source_port

boolean

Match transport layer source port.

Choices:

  • false

  • true

name

string / required

Name of the flow record.

samplers

list / elements=dictionary

Sampler definitions.

description

string

Human-readable description of the sampler.

mode

string

Sampling mode.

Choices:

  • "random"

  • "deterministic"

name

string / required

Name of the sampler.

window_size

integer

Sampling rate expressed as N in “1 out-of N”.

running_config

string

This option is used only with state parsed.

The value of this option should be the output of the command show running-config | section ^(flow|sampler) on the device.

The state parsed reads the configuration from running_config 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.

State merged merges the provided config into the existing device config.

State replaced converges only the records, exporters, samplers and monitors named in config and leaves other entities untouched.

State overridden additionally removes every record, exporter, sampler and monitor that is not named in config. Removing a monitor that is applied to interfaces is service-affecting.

State deleted removes the specified (or all) flow monitor entities. Deletion order is monitors → exporters → samplers → records to respect dependencies.

State rendered, gathered and parsed do not perform any change on the device.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "rendered"

  • "gathered"

  • "parsed"

Notes

Note

  • Tested against Cisco IOS XE.

  • This module works with connection network_cli. See https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html

  • The module examples use callback plugin (stdout_callback = yaml) to generate task output in yaml format.

  • Some options (cache type permanent, transport tcp) are only supported on router platforms.

  • Catalyst 9300 accepts cache entries without an error but does not keep it in the running configuration. A monitor that sets cache.entries is therefore reported as changed on every run on that platform, so leave it out there. The cache timeouts are kept.

  • The platforms accept different collect options. The module does not check the platform, the device rejects an option it does not support when the commands are applied. Commands sent before the rejected one stay applied.

  • Tested on a Catalyst 9300 (IOS XE 17.12.4 and 17.18.4) and a Catalyst 9600 (C9606R, IOS XE 17.12.5 and 17.12.6), all with Network Advantage and DNA Advantage licenses. The license does not change which options are accepted, and IOS XE 17.12.5 and 17.12.6 gave the same results.

  • Catalyst 9600 accepts counter_bytes and counter_packets (collect counter bytes, collect counter packets) and timestamp_sys_uptime_first and timestamp_sys_uptime_last. Existing flow records on these devices use them.

  • Catalyst 9300 rejects counter_bytes and counter_packets with % Incomplete command, and rejects timestamp_sys_uptime_first and timestamp_sys_uptime_last as invalid input. Use counter_bytes_long, counter_bytes_layer2_long, counter_packets_long, timestamp_absolute_first and timestamp_absolute_last there.

  • Both Catalyst 9300 and Catalyst 9600 reject counter_bytes_layer2 (it needs long, use counter_bytes_layer2_long), routing_source_as and routing_destination_as without qualifier, and the routing_source_as_peer and routing_destination_as_peer variants, all with % Incomplete command. These options are for other platforms.

  • Accepted on both Catalyst 9300 and Catalyst 9600, so these are the safe choice on both, counter_bytes_long, counter_bytes_layer2_long, counter_packets_long, timestamp_absolute_first, timestamp_absolute_last, routing_source_as_4octet, routing_destination_as_4octet, routing_next_hop_ipv4, transport_tcp_flags, interface_input and interface_output.

  • IOS XE (Catalyst 9300 and 9600) does not show values that are the default in the running configuration, for example cache timeout inactive 15, cache timeout active 1800 and the exporter export-protocol netflow-v9, template data timeout 600, ttl 255 and dscp 0. The module treats these as equal to an unset value, so specifying them does not cause a change on every run.

  • IOS XE ignores changes to a flow record, without reporting an error, while a flow monitor that uses it exists. To change a record, delete the flow monitors using it first, or use a new record name.

Examples

# Using state: merged

# Before state:
# router# show running-config | section ^(flow|sampler)
# (empty)

- name: Configure Flexible NetFlow (Catalyst 9600 and routers, see the notes for Catalyst 9300)
  cisco.ios.ios_flow_monitor_global:
    config:
      records:
        - name: FLOW_RECORD_IPV4
          match:
            ipv4_tos: true
            ipv4_protocol: true
            ipv4_source_address: true
            ipv4_destination_address: true
            transport_source_port: true
            transport_destination_port: true
            flow_direction: true
            interface_output: true
          collect:
            routing_source_as_4octet: true
            routing_destination_as_4octet: true
            routing_next_hop_ipv4: true
            transport_tcp_flags: true
            counter_bytes: true
            counter_packets: true
            timestamp_sys_uptime_first: true
            timestamp_sys_uptime_last: true
            interface_input: true
      exporters:
        - name: FLOW_EXPORTER_1
          destination: 192.0.2.1
          vrf: MGMT
          source: Loopback0
          transport:
            protocol: udp
            port: 2055
          options:
            sampler_table_timeout: 10
      samplers:
        - name: FLOW_SAMPLER
          mode: random
          window_size: 1000
      monitors:
        - name: FLOW_MONITOR_OUT
          exporters:
            - FLOW_EXPORTER_1
          cache:
            timeout_inactive: 10
            timeout_active: 60
          record: FLOW_RECORD_IPV4
    state: merged

# Commands fired:
# flow record FLOW_RECORD_IPV4
#  match ipv4 tos
#  match ipv4 protocol
#  match ipv4 source address
#  match ipv4 destination address
#  match transport source-port
#  match transport destination-port
#  match flow direction
#  match interface output
#  collect routing source as 4-octet
#  collect routing destination as 4-octet
#  collect routing next-hop address ipv4
#  collect transport tcp flags
#  collect counter bytes
#  collect counter packets
#  collect timestamp sys-uptime first
#  collect timestamp sys-uptime last
#  collect interface input
# flow exporter FLOW_EXPORTER_1
#  destination 192.0.2.1 vrf MGMT
#  source Loopback0
#  transport udp 2055
#  option sampler-table timeout 10
# sampler FLOW_SAMPLER
#  mode random 1 out-of 1000
# flow monitor FLOW_MONITOR_OUT
#  exporter FLOW_EXPORTER_1
#  cache timeout inactive 10
#  cache timeout active 60
#  record FLOW_RECORD_IPV4

# Using state: merged — Catalyst 9300 flow record
#
# Catalyst 9300 rejects the counter_bytes, counter_packets and timestamp_sys_uptime options
# used in the first example, it needs the long counters and absolute timestamps.

- name: Configure a flow record on a Catalyst 9300
  cisco.ios.ios_flow_monitor_global:
    config:
      records:
        - name: FLOW_RECORD_IPV4
          match:
            ipv4_tos: true
            ipv4_protocol: true
            ipv4_source_address: true
            ipv4_destination_address: true
            transport_source_port: true
            transport_destination_port: true
            flow_direction: true
            interface_output: true
          collect:
            routing_source_as_4octet: true
            routing_destination_as_4octet: true
            routing_next_hop_ipv4: true
            transport_tcp_flags: true
            counter_bytes_layer2_long: true
            counter_packets_long: true
            timestamp_absolute_first: true
            timestamp_absolute_last: true
            interface_input: true
    state: merged

# Commands fired:
# flow record FLOW_RECORD_IPV4
#  match ipv4 tos
#  match ipv4 protocol
#  match ipv4 source address
#  match ipv4 destination address
#  match transport source-port
#  match transport destination-port
#  match flow direction
#  match interface output
#  collect routing source as 4-octet
#  collect routing destination as 4-octet
#  collect routing next-hop address ipv4
#  collect transport tcp flags
#  collect counter bytes layer2 long
#  collect counter packets long
#  collect timestamp absolute first
#  collect timestamp absolute last
#  collect interface input

# Using state: merged — dual exporter (two collectors)

- name: Configure flow monitor with dual exporters
  cisco.ios.ios_flow_monitor_global:
    config:
      exporters:
        - name: FLOW_EXPORTER_1
          destination: 192.0.2.1
          vrf: MGMT
          source: Loopback0
          transport:
            protocol: udp
            port: 9996
          options:
            sampler_table_timeout: 2000
            template_data_timeout: 10000
        - name: FLOW_EXPORTER_2
          destination: 192.0.2.2
          vrf: MGMT
          source: Loopback0
          transport:
            protocol: udp
            port: 9996
          options:
            sampler_table_timeout: 2000
            template_data_timeout: 10000
      monitors:
        - name: FLOW_MONITOR_IN
          exporters:
            - FLOW_EXPORTER_1
            - FLOW_EXPORTER_2
          record: FLOW_RECORD_IPV4
    state: merged

# Using state: deleted

- name: Remove all flow monitor configuration
  cisco.ios.ios_flow_monitor_global:
    state: deleted

# Using state: gathered

- name: Gather existing flow monitor configuration
  cisco.ios.ios_flow_monitor_global:
    state: gathered

# Using state: rendered

- name: Render commands without connecting to device
  cisco.ios.ios_flow_monitor_global:
    config:
      samplers:
        - name: FLOW_SAMPLER
          mode: random
          window_size: 1000
    state: rendered

# Using state: parsed

- name: Parse device config into structured data
  cisco.ios.ios_flow_monitor_global:
    running_config: |
      flow record FLOW_RECORD_IPV4
       match ipv4 source address
       match ipv4 destination address
       collect counter bytes
       collect counter packets
      sampler FLOW_SAMPLER
       mode random 1 out-of 1000
      flow monitor FLOW_MONITOR_OUT
       record FLOW_RECORD_IPV4
    state: parsed

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

after

dictionary

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

dictionary

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: always

Sample: ["flow record FLOW_RECORD_IPV4", " match ipv4 source address", " collect counter bytes"]

gathered

dictionary

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

dictionary

The device native config provided in running_config option, parsed into structured data.

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 state=rendered option.

Returned: when state is rendered

Sample: ["flow record FLOW_RECORD_IPV4", " match ipv4 source address"]

Authors

  • Jørgen Spange (@jorgenspange)