100%

meraki_switch_routing

module
Manage Meraki switch routing (multicast and OSPF)
Added in version 0.1.0

Synopsis

  • Manage Meraki switch routing configuration for a network.
  • Singleton per network (multicast + OSPF settings).
  • Supports merged, replaced, and gathered states.

Author

Cisco Meraki

Parameters

config (list/dict)

Switch routing configuration (singleton).

areas (list/dict)

OSPF areas.

dead_timer_in_seconds (int)

OSPF dead timer in seconds.

default_settings (dict)

Default multicast settings for the network.

enabled (bool)

Enable OSPF routing.

hello_timer_in_seconds (int)

OSPF hello timer in seconds.

md5_authentication_enabled (bool)

Enable MD5 authentication for OSPF.

md5_authentication_key (dict)

MD5 authentication credentials.

overrides (list/dict)

Multicast overrides per switch/stack/profile.

network_id (str) required

The network ID.

state (str)
mergedreplacedgathered

The state of the resource.

Sample Task

A template task showing all available parameters with their defaults or example values.

- name: Meraki Switch Routing task
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "192.168.1.0/24"
    config:
      - areas:
          - {}
        dead_timer_in_seconds: 0
        default_settings: {}
        enabled: true
        hello_timer_in_seconds: 0
        md5_authentication_enabled: true
        md5_authentication_key: {}
        overrides:
          - {}
    state: merged
- name: Meraki Switch Routing task
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "192.168.1.0/24"
    config:  # optional
      - areas:  # optional
          - {}
        dead_timer_in_seconds: 0  # optional
        default_settings: {}  # optional
        enabled: true  # optional
        hello_timer_in_seconds: 0  # optional
        md5_authentication_enabled: true  # optional
        md5_authentication_key: {}  # optional
        overrides:  # optional
          - {}
    state: merged  # optional
- name: Meraki Switch Routing task
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "192.168.1.0/24"  # (str, required) The network ID.
    config:  # (list, optional) Switch routing configuration (singleton).
      - areas:  # (list, optional) OSPF areas.
          - {}
        dead_timer_in_seconds: 0  # (int, optional) OSPF dead timer in seconds.
        default_settings: {}  # (dict, optional) Default multicast settings for the network.
        enabled: true  # (bool, optional) Enable OSPF routing.
        hello_timer_in_seconds: 0  # (int, optional) OSPF hello timer in seconds.
        md5_authentication_enabled: true  # (bool, optional) Enable MD5 authentication for OSPF.
        md5_authentication_key: {}  # (dict, optional) MD5 authentication credentials.
        overrides:  # (list, optional) Multicast overrides per switch/stack/profile.
          - {}
    state: merged  # (str, optional) The state of the resource.

Examples

Define Expected Configuration
- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      enabled: true
      hello_timer_in_seconds: 1
      dead_timer_in_seconds: 1
      md5_authentication_enabled: true
Create Switch_routing With Merged State
- name: Create switch_routing with merged state
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: merged
    config:
      - "{{ expected_config }}"
  register: merge_result
Assert Resource Was Created
- name: Assert resource was created
  ansible.builtin.assert:
    that:
      - merge_result is changed
      - merge_result.config | length == 1
Compare Expected Paths To Result (subset Check)
- name: Compare expected paths to result (subset check)
  ansible.builtin.set_fact:
    path_check: "{{ expected_paths | cisco.meraki_rm.path_contained_in(result_paths) }}"
  vars:
    expected_paths: "{{ expected_config | ansible.utils.to_paths }}"
    result_paths: "{{ merge_result.config[0] | ansible.utils.to_paths }}"
Assert All Expected Fields Are Present And Match
- name: Assert all expected fields are present and match
  ansible.builtin.assert:
    that: path_check.contained | bool
    success_msg: "{{ success_msg }}"
    fail_msg: "{{ fail_msg }}"
  vars:
    success_msg: "All expected fields match. Extras: {{ path_check.extras }}"
    fail_msg: "Missing or mismatch: {{ path_check.missing }}. Extras: {{ path_check.extras }}"
Task Output:
# Manage Meraki switch routing (multicast and OSPF) — full resource replacement
Define Replacement Configuration
- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      enabled: false
      hello_timer_in_seconds: 1
      dead_timer_in_seconds: 1
      md5_authentication_enabled: true
Replace Switch_routing Configuration
- name: Replace switch_routing configuration
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: replaced
    config:
      - "{{ expected_config }}"
  register: replace_result
Assert Resource Was Replaced
- name: Assert resource was replaced
  ansible.builtin.assert:
    that:
      - replace_result is changed
      - replace_result.config | length == 1
Compare Expected Paths To Result (subset Check)
- name: Compare expected paths to result (subset check)
  ansible.builtin.set_fact:
    path_check: "{{ expected_paths | cisco.meraki_rm.path_contained_in(result_paths) }}"
  vars:
    expected_paths: "{{ expected_config | ansible.utils.to_paths }}"
    result_paths: "{{ replace_result.config[0] | ansible.utils.to_paths }}"
Assert All Expected Fields Are Present And Match
- name: Assert all expected fields are present and match
  ansible.builtin.assert:
    that: path_check.contained | bool
    success_msg: "{{ success_msg }}"
    fail_msg: "{{ fail_msg }}"
  vars:
    success_msg: "All expected fields match. Extras: {{ path_check.extras }}"
    fail_msg: "Missing or mismatch: {{ path_check.missing }}. Extras: {{ path_check.extras }}"
Task Output:
# Manage Meraki switch routing (multicast and OSPF) — gather current configuration
Gather Current Switch_routing Configuration
- name: Gather current switch_routing configuration
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: gathered
  register: gathered
Assert Gathered Config Is Not Empty
- name: Assert gathered config is not empty
  ansible.builtin.assert:
    that:
      - gathered.config is defined
      - gathered.config | length > 0
    fail_msg: "Gathered config is empty — expected at least one resource"
Display Gathered Configuration
- name: Display gathered configuration
  ansible.builtin.debug:
    var: gathered.config
---
# Manage Meraki switch routing (multicast and OSPF) — create or update

- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      enabled: true
      hello_timer_in_seconds: 1
      dead_timer_in_seconds: 1
      md5_authentication_enabled: true

- name: Create switch_routing with merged state
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: merged
    config:
      - "{{ expected_config }}"
  register: merge_result

- name: Assert resource was created
  ansible.builtin.assert:
    that:
      - merge_result is changed
      - merge_result.config | length == 1

- name: Compare expected paths to result (subset check)
  ansible.builtin.set_fact:
    path_check: "{{ expected_paths | cisco.meraki_rm.path_contained_in(result_paths) }}"
  vars:
    expected_paths: "{{ expected_config | ansible.utils.to_paths }}"
    result_paths: "{{ merge_result.config[0] | ansible.utils.to_paths }}"

- name: Assert all expected fields are present and match
  ansible.builtin.assert:
    that: path_check.contained | bool
    success_msg: "{{ success_msg }}"
    fail_msg: "{{ fail_msg }}"
  vars:
    success_msg: "All expected fields match. Extras: {{ path_check.extras }}"
    fail_msg: "Missing or mismatch: {{ path_check.missing }}. Extras: {{ path_check.extras }}"

# Manage Meraki switch routing (multicast and OSPF) — full resource replacement

- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      enabled: false
      hello_timer_in_seconds: 1
      dead_timer_in_seconds: 1
      md5_authentication_enabled: true

- name: Replace switch_routing configuration
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: replaced
    config:
      - "{{ expected_config }}"
  register: replace_result

- name: Assert resource was replaced
  ansible.builtin.assert:
    that:
      - replace_result is changed
      - replace_result.config | length == 1

- name: Compare expected paths to result (subset check)
  ansible.builtin.set_fact:
    path_check: "{{ expected_paths | cisco.meraki_rm.path_contained_in(result_paths) }}"
  vars:
    expected_paths: "{{ expected_config | ansible.utils.to_paths }}"
    result_paths: "{{ replace_result.config[0] | ansible.utils.to_paths }}"

- name: Assert all expected fields are present and match
  ansible.builtin.assert:
    that: path_check.contained | bool
    success_msg: "{{ success_msg }}"
    fail_msg: "{{ fail_msg }}"
  vars:
    success_msg: "All expected fields match. Extras: {{ path_check.extras }}"
    fail_msg: "Missing or mismatch: {{ path_check.missing }}. Extras: {{ path_check.extras }}"

# Manage Meraki switch routing (multicast and OSPF) — gather current configuration

- name: Gather current switch_routing configuration
  cisco.meraki_rm.meraki_switch_routing:
    network_id: "N_123456789012345678"
    state: gathered
  register: gathered

- name: Assert gathered config is not empty
  ansible.builtin.assert:
    that:
      - gathered.config is defined
      - gathered.config | length > 0
    fail_msg: "Gathered config is empty — expected at least one resource"

- name: Display gathered configuration
  ansible.builtin.debug:
    var: gathered.config

Return Values

config
list — returned: always
The resulting resource configuration.