100%

meraki_organization_policy_objects

module
Manage Meraki organization policy objects
Added in version 0.1.0

Synopsis

  • Manage Meraki organization policy objects.
  • Supports merged, replaced, overridden, deleted, and gathered states.

Author

Cisco Meraki

Parameters

config (list/dict)

List of policy object configurations.

category (str)
adaptivePolicynetwork

Category of policy object.

cidr (str)

CIDR value (for cidr type).

fqdn (str)

Fully qualified domain name (for fqdn type).

group_ids (list/str)

IDs of policy object groups this object belongs to.

ip (str)

IP address (for ipAndMask type).

mask (str)

Subnet mask (for ipAndMask type).

name (str)

Name of the policy object.

policy_object_id (str)

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

Provide only to disambiguate when duplicate names exist.

type (str)
adaptivePolicyIpv4CidrcidrfqdnipAndMask

Type of policy object.

organization_id (str) required

The organization ID.

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 Organization Policy Objects task
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "organization_id_value"
    config:
      - category: adaptivePolicy
        cidr: "cidr_value"
        fqdn: "fqdn_value"
        group_ids:
          - "group_ids_item"
        ip: "192.168.1.1"
        mask: "mask_value"
        name: "example_name"
        policy_object_id: "policy_object_id_value"
        type: adaptivePolicyIpv4Cidr
    state: merged
- name: Meraki Organization Policy Objects task
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "organization_id_value"
    config:  # optional
      - category: adaptivePolicy  # optional
        cidr: "cidr_value"  # optional
        fqdn: "fqdn_value"  # optional
        group_ids:  # optional
          - "group_ids_item"
        ip: "192.168.1.1"  # optional
        mask: "mask_value"  # optional
        name: "example_name"  # optional
        policy_object_id: "policy_object_id_value"  # optional
        type: adaptivePolicyIpv4Cidr  # optional
    state: merged  # optional
- name: Meraki Organization Policy Objects task
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "organization_id_value"  # (str, required) The organization ID.
    config:  # (list, optional) List of policy object configurations.
      - category: adaptivePolicy  # (str, optional) Category of policy object.
        cidr: "cidr_value"  # (str, optional) CIDR value (for cidr type).
        fqdn: "fqdn_value"  # (str, optional) Fully qualified domain name (for fqdn type).
        group_ids:  # (list, optional) IDs of policy object groups this object belongs to.
          - "group_ids_item"
        ip: "192.168.1.1"  # (str, optional) IP address (for ipAndMask type).
        mask: "mask_value"  # (str, optional) Subnet mask (for ipAndMask type).
        name: "example_name"  # (str, optional) Name of the policy object.
        policy_object_id: "policy_object_id_value"  # (str, optional) Server-assigned ID, resolved automatically by matching on...
        type: adaptivePolicyIpv4Cidr  # (str, optional) Type of policy object.
    state: merged  # (str, optional) The state of the resource.

Notes

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

Examples

Define Expected Configuration
- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      category: adaptivePolicy
      type: adaptivePolicyIpv4Cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24
Create Organization_policy_objects With Merged State
- name: Create organization_policy_objects with merged state
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — full resource replacement
Define Replacement Configuration
- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      category: network
      type: cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24
Replace Organization_policy_objects Configuration
- name: Replace organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — 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
      category: network
      type: cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24
Override All Organization_policy_objects — Desired State Only
- name: Override all organization_policy_objects — desired state only
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — gather current configuration
Gather Current Organization_policy_objects Configuration
- name: Gather current organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — remove configuration
Define Resource To Delete
- name: Define resource to delete
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
Delete Organization_policy_objects Configuration
- name: Delete organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — create or update

- name: Define expected configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      category: adaptivePolicy
      type: adaptivePolicyIpv4Cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24

- name: Create organization_policy_objects with merged state
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — full resource replacement

- name: Define replacement configuration
  ansible.builtin.set_fact:
    expected_config:
      name: Test-Config
      category: network
      type: cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24

- name: Replace organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — 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
      category: network
      type: cidr
      cidr: 192.168.128.0/24
      fqdn: example.com
      ip: 10.0.0.1
      mask: 24

- name: Override all organization_policy_objects — desired state only
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — gather current configuration

- name: Gather current organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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 organization policy objects — remove configuration

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

- name: Delete organization_policy_objects configuration
  cisco.meraki_rm.meraki_organization_policy_objects:
    organization_id: "123456"
    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.