100%

meraki_device_switch_routes

module
Manage Meraki device switch routing interfaces
Added in version 0.1.0

Synopsis

  • Manage Meraki device switch routing interfaces (L3 interfaces).
  • Scope is device serial. Supports merged, replaced, deleted, and gathered states.

Author

Cisco Meraki

Parameters

config (list/dict)

List of switch routing interface configurations.

default_gateway (str)

IPv4 default gateway.

dhcp_mode (str)

DHCP mode for the interface.

dhcp_relay_server_ips (list/str)

DHCP relay server IPs.

interface_id (str)

Server-assigned ID, resolved automatically by matching on name.

Provide only to disambiguate when duplicate names exist.

interface_ip (str)

IPv4 address.

multicast_routing (str)

Multicast routing status.

name (str)

Interface name.

ospf_settings (dict)

IPv4 OSPF settings.

subnet (str)

IPv4 subnet.

vlan_id (int)

VLAN ID.

serial (str) required

Device serial number.

state (str)
mergedreplacedoverriddendeletedgathered

The state of the resource.

Sample Task

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

- name: Meraki Device Switch Routes task
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "serial_value"
    config:
      - default_gateway: "default_gateway_value"
        dhcp_mode: "0644"
        dhcp_relay_server_ips:
          - "dhcp_relay_server_ips_item"
        interface_id: "eth0"
        interface_ip: "eth0"
        multicast_routing: "multicast_routing_value"
        name: "example_name"
        ospf_settings: {}
        subnet: "192.168.1.0/24"
        vlan_id: 0
    state: merged
- name: Meraki Device Switch Routes task
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "serial_value"
    config:  # optional
      - default_gateway: "default_gateway_value"  # optional
        dhcp_mode: "0644"  # optional
        dhcp_relay_server_ips:  # optional
          - "dhcp_relay_server_ips_item"
        interface_id: "eth0"  # optional
        interface_ip: "eth0"  # optional
        multicast_routing: "multicast_routing_value"  # optional
        name: "example_name"  # optional
        ospf_settings: {}  # optional
        subnet: "192.168.1.0/24"  # optional
        vlan_id: 0  # optional
    state: merged  # optional
- name: Meraki Device Switch Routes task
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "serial_value"  # (str, required) Device serial number.
    config:  # (list, optional) List of switch routing interface configurations.
      - default_gateway: "default_gateway_value"  # (str, optional) IPv4 default gateway.
        dhcp_mode: "0644"  # (str, optional) DHCP mode for the interface.
        dhcp_relay_server_ips:  # (list, optional) DHCP relay server IPs.
          - "dhcp_relay_server_ips_item"
        interface_id: "eth0"  # (str, optional) Server-assigned ID, resolved automatically by matching on...
        interface_ip: "eth0"  # (str, optional) IPv4 address.
        multicast_routing: "multicast_routing_value"  # (str, optional) Multicast routing status.
        name: "example_name"  # (str, optional) Interface name.
        ospf_settings: {}  # (dict, optional) IPv4 OSPF settings.
        subnet: "192.168.1.0/24"  # (str, optional) IPv4 subnet.
        vlan_id: 0  # (int, optional) VLAN ID.
    state: merged  # (str, optional) The state of the resource.

Notes

  • Canonical key: name — identifies the resource in playbooks.
  • System key: interface_id — server-assigned, resolved automatically from gathered state.
  • Users do not need to provide interface_id unless disambiguating duplicate names.

Examples

Define Expected Configuration
- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 192.168.128.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example
Create Device_switch_routes With Merged State
- name: Create device_switch_routes with merged state
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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 device switch routing interfaces — full resource replacement
Define Replacement Configuration
- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 10.20.0.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example
Replace Device_switch_routes Configuration
- name: Replace device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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 device switch routing interfaces — override all instances # Ensures ONLY these resources exist; any not listed are deleted.
Define Desired-state Configuration
- name: Define desired-state configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 10.20.0.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example
Override All Device_switch_routes — Desired State Only
- name: Override all device_switch_routes — desired state only
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    state: overridden
    config:
      - "{{ expected_config }}"
  register: override_result
Assert Resources Were Overridden
- name: Assert resources were overridden
  ansible.builtin.assert:
    that:
      - override_result is changed
      - override_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: "{{ override_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 device switch routing interfaces — gather current configuration
Gather Current Device_switch_routes Configuration
- name: Gather current device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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
Task Output:
# Manage Meraki device switch routing interfaces — remove configuration
Define Resource To Delete
- name: Define resource to delete
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
Delete Device_switch_routes Configuration
- name: Delete device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    state: deleted
    config:
      - "{{ expected_config }}"
  register: delete_result
Assert Resource Was Deleted
- name: Assert resource was deleted
  ansible.builtin.assert:
    that:
      - delete_result is changed
      - delete_result is not failed
---
# Manage Meraki device switch routing interfaces — create or update

- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 192.168.128.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example

- name: Create device_switch_routes with merged state
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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 device switch routing interfaces — full resource replacement

- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 10.20.0.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example

- name: Replace device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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 device switch routing interfaces — override all instances
# Ensures ONLY these resources exist; any not listed are deleted.

- name: Define desired-state configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      subnet: 10.20.0.0/24
      interface_ip: 10.0.0.1
      default_gateway: 10.0.0.1
      vlan_id: "100"
      multicast_routing: example
      dhcp_mode: example

- name: Override all device_switch_routes — desired state only
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    state: overridden
    config:
      - "{{ expected_config }}"
  register: override_result

- name: Assert resources were overridden
  ansible.builtin.assert:
    that:
      - override_result is changed
      - override_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: "{{ override_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 device switch routing interfaces — gather current configuration

- name: Gather current device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    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

# Manage Meraki device switch routing interfaces — remove configuration

- name: Define resource to delete
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config

- name: Delete device_switch_routes configuration
  cisco.meraki_rm.meraki_device_switch_routes:
    serial: "Q2XX-XXXX-XXXX"
    state: deleted
    config:
      - "{{ expected_config }}"
  register: delete_result

- name: Assert resource was deleted
  ansible.builtin.assert:
    that:
      - delete_result is changed
      - delete_result is not failed

Return Values

config
list — returned: always
The resulting resource configuration.