1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

meraki - Unchanged requests now return the original data (#53576)

* Unchanged requests now return the original data

* Add changelog fragment

* Add integration tests for returned data for meraki_network

* Add integration tests for returned data

* Improve idempoetent output
- Make MX l3 rules always show default rule
- Add integration tests

* Add integration tests for returned data on meraki_network

* Improved idempotency in a few modules and improved tests
This commit is contained in:
Kevin Breit 2019-05-16 22:04:16 -05:00 committed by Trishna Guha
parent a3c3fd91f8
commit 2a187f362a
29 changed files with 167 additions and 96 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- "meraki_* - Meraki modules now return data when no changes are made."

View file

@ -354,7 +354,6 @@ def create_admin(meraki, org_id, name, email):
if not meraki.params['networks']:
payload['networks'] = []
if meraki.is_update_required(is_admin_existing, payload) is True:
# meraki.fail_json(msg='Update is required!!!', original=is_admin_existing, proposed=payload)
path = meraki.construct_path('update', function='admin', org_id=org_id) + is_admin_existing['id']
r = meraki.request(path,
method='PUT',
@ -364,7 +363,7 @@ def create_admin(meraki, org_id, name, email):
meraki.result['changed'] = True
return r
else:
# meraki.fail_json(msg='No update is required!!!')
meraki.result['data'] = is_admin_existing
return -1

View file

@ -247,6 +247,8 @@ def main():
meraki.fail_json(msg='Unable to bind configuration template to network')
meraki.result['changed'] = True
meraki.result['data'] = template_bind
else:
meraki.result['data'] = {}
elif meraki.params['state'] == 'absent':
if not meraki.params['net_name'] and not meraki.params['net_id']:
meraki.result['data'] = delete_template(meraki,
@ -266,6 +268,8 @@ def main():
meraki.fail_json(msg='Unable to unbind configuration template from network')
meraki.result['changed'] = True
meraki.result['data'] = config_unbind
else:
meraki.result['data'] = {}
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -210,6 +210,8 @@ def main():
response = meraki.request(path, method='PUT', payload=json.dumps(payload))
meraki.result['data'] = response
meraki.result['changed'] = True
else:
meraki.result['data'] = current
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -378,6 +378,8 @@ def main():
updated_device.append(meraki.request(path, method='PUT', payload=json.dumps(payload)))
meraki.result['data'] = updated_device
meraki.result['changed'] = True
else:
meraki.result['data'] = device_data
else:
if net_id is None:
device_list = get_org_devices(meraki, org_id)

View file

@ -20,6 +20,7 @@ short_description: Manage MR access point layer 3 firewalls in the Meraki cloud
version_added: "2.7"
description:
- Allows for creation, management, and visibility into layer 3 firewalls implemented on Meraki MR access points.
- Module is not idempotent as of current release.
options:
state:
description:
@ -278,6 +279,8 @@ def main():
if meraki.status == 200:
meraki.result['data'] = response
meraki.result['changed'] = True
else:
meraki.result['data'] = rules
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -303,7 +303,6 @@ def main():
update = False
if meraki.params['syslog_default_rule'] is not None:
payload['syslogDefaultRule'] = meraki.params['syslog_default_rule']
# meraki.fail_json(msg='Payload', payload=payload)
try:
if len(rules) - 1 != len(payload['rules']): # Quick and simple check to avoid more processing
update = True
@ -311,19 +310,21 @@ def main():
if rules[len(rules) - 1]['syslogEnabled'] != meraki.params['syslog_default_rule']:
update = True
if update is False:
default_rule = rules[len(rules) - 1].copy()
del rules[len(rules) - 1] # Remove default rule for comparison
for r in range(len(rules) - 1):
if meraki.is_update_required(rules[r], payload['rules'][r]) is True:
update = True
rules.append(default_rule)
except KeyError:
pass
# if meraki.params['syslog_default_rule']:
# meraki.fail_json(msg='Compare', original=rules, proposed=payload)
if update is True:
response = meraki.request(path, method='PUT', payload=json.dumps(payload))
if meraki.status == 200:
meraki.result['data'] = response
meraki.result['changed'] = True
else:
meraki.result['data'] = rules
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -316,7 +316,6 @@ def main():
if meraki.status == 200:
meraki.result['data'] = r
meraki.result['changed'] = True
else: # Update existing network
net = meraki.get_net(meraki.params['org_name'], meraki.params['net_name'], data=nets)
if meraki.params['enable_vlans'] is not None:
@ -344,6 +343,8 @@ def main():
if meraki.status == 200:
meraki.result['data'] = r
meraki.result['changed'] = True
else:
meraki.result['data'] = net
elif meraki.params['state'] == 'absent':
if is_net_valid(meraki, meraki.params['net_name'], nets) is True:
net_id = meraki.get_net_id(net_name=meraki.params['net_name'],

View file

@ -207,12 +207,8 @@ def main():
payload = {'name': meraki.params['org_name'],
'id': meraki.params['org_id'],
}
if meraki.is_update_required(
get_org(
meraki,
meraki.params['org_id'],
orgs),
payload):
original = get_org(meraki, meraki.params['org_id'], orgs)
if meraki.is_update_required(original, payload):
response = meraki.request(meraki.construct_path('update',
org_id=meraki.params['org_id']
),
@ -222,6 +218,9 @@ def main():
meraki.fail_json(msg='Organization update failed')
meraki.result['data'] = response
meraki.result['changed'] = True
else:
meraki.result['data'] = original
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results
meraki.exit_json(**meraki.result)

View file

@ -209,7 +209,8 @@ def set_snmp(meraki, org_id):
if meraki.status == 200:
meraki.result['changed'] = True
return r
return -1
else:
return snmp
def main():

View file

@ -519,6 +519,8 @@ def main():
result = meraki.request(path, 'PUT', payload=json.dumps(payload))
meraki.result['data'] = result
meraki.result['changed'] = True
else:
meraki.result['data'] = original
elif meraki.params['state'] == 'absent':
ssids = get_ssids(meraki, net_id)
ssid_id = meraki.params['number']

View file

@ -363,6 +363,8 @@ def main():
path = meraki.construct_path('update', net_id=net_id, custom={'route_id': meraki.params['route_id']})
meraki.result['data'] = meraki.request(path, method="PUT", payload=json.dumps(payload))
meraki.result['changed'] = True
else:
meraki.result['data'] = existing_route
else:
if module.check_mode:
meraki.result['data'] = payload

View file

@ -384,6 +384,8 @@ def main():
response = meraki.request(path, method='PUT', payload=json.dumps(payload))
meraki.result['data'] = response
meraki.result['changed'] = True
else:
meraki.result['data'] = original
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -278,6 +278,8 @@ def main():
if meraki.status == 200:
meraki.result['data'] = r
meraki.result['changed'] = True
else:
meraki.result['data'] = original
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results

View file

@ -397,6 +397,8 @@ def main():
response = meraki.request(path, method='PUT', payload=json.dumps(payload))
meraki.result['changed'] = True
meraki.result['data'] = response
else:
meraki.result['data'] = original
elif meraki.params['state'] == 'absent':
if is_vlan_valid(meraki, net_id, meraki.params['vlan_id']):
path = meraki.construct_path('delete', net_id=net_id) + str(meraki.params['vlan_id'])

View file

@ -174,6 +174,7 @@
- assert:
that:
- update_network_idempotent.changed == false
- update_network_idempotent.data is defined
- name: Create administrator with invalid network
meraki_admin:

View file

@ -4,39 +4,39 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
# - name: Test an API key is provided
# fail:
# msg: Please define an API key
# when: auth_key is not defined
- name: Test an API key is provided
fail:
msg: Please define an API key
when: auth_key is not defined
# - name: Use an invalid domain
# meraki_config_template:
# auth_key: '{{ auth_key }}'
# host: marrrraki.com
# state: query
# org_name: DevTestOrg
# output_level: debug
# delegate_to: localhost
# register: invalid_domain
# ignore_errors: yes
- name: Use an invalid domain
meraki_config_template:
auth_key: '{{ auth_key }}'
host: marrrraki.com
state: query
org_name: DevTestOrg
output_level: debug
delegate_to: localhost
register: invalid_domain
ignore_errors: yes
# - name: Connection assertions
# assert:
# that:
# - '"Failed to connect to" in invalid_domain.msg'
- name: Connection assertions
assert:
that:
- '"Failed to connect to" in invalid_domain.msg'
- name: Query all configuration templates
meraki_config_template:
auth_key: '{{auth_key}}'
state: query
org_name: DevTestOrg
org_name: '{{test_org_name}}'
register: get_all
- name: Delete non-existant configuration template
meraki_config_template:
auth_key: '{{auth_key}}'
state: absent
org_name: DevTestOrg
org_name: '{{test_org_name}}'
config_template: FakeConfigTemplate
register: deleted
ignore_errors: yes
@ -142,7 +142,8 @@
- assert:
that:
bind_id_idempotent.changed == False
- bind_id_idempotent.changed == False
- bind_id_idempotent.data is defined
- name: Unbind a template to a network via id
meraki_config_template:

View file

@ -4,26 +4,37 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
# - name: Test an API key is provided
# fail:
# msg: Please define an API key
# when: auth_key is not defined
- name: Test an API key is provided
fail:
msg: Please define an API key
when: auth_key is not defined
# - name: Use an invalid domain
# meraki_config_template:
# auth_key: '{{ auth_key }}'
# host: marrrraki.com
# state: query
# org_name: DevTestOrg
# output_level: debug
# delegate_to: localhost
# register: invalid_domain
# ignore_errors: yes
- name: Use an invalid domain
meraki_config_template:
auth_key: '{{ auth_key }}'
host: marrrraki.com
state: query
org_name: DevTestOrg
output_level: debug
delegate_to: localhost
register: invalid_domain
ignore_errors: yes
# - name: Connection assertions
# assert:
# that:
# - '"Failed to connect to" in invalid_domain.msg'
- name: Connection assertions
assert:
that:
- '"Failed to connect to" in invalid_domain.msg'
- name: Create network with type switch
meraki_network:
auth_key: '{{ auth_key }}'
state: present
org_name: '{{test_org_name}}'
net_name: '{{test_net_name}}'
type: appliance
timezone: America/Chicago
delegate_to: localhost
register: create_net_appliance
- name: Set single allowed URL pattern
meraki_content_filtering:
@ -58,6 +69,7 @@
- assert:
that:
- single_allowed_idempotent.changed == False
- single_allowed_idempotent.data is defined
- name: Set single blocked URL pattern
meraki_content_filtering:

View file

@ -183,6 +183,7 @@
tags: recently-added
state: present
move_map_marker: True
note: Test device notes
delegate_to: localhost
register: update_device_idempotent
@ -192,6 +193,7 @@
- assert:
that:
- update_device_idempotent.changed == False
- update_device_idempotent.data is defined
always:
- name: Remove a device from a network

View file

@ -41,6 +41,7 @@
that:
- create_one.data.0.comment == 'Integration test rule'
- create_one.data.1.policy == 'deny'
- create_one.data is defined
- name: Enable local LAN access
meraki_mr_l3_firewall:

View file

@ -4,37 +4,37 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- block:
# - name: Test an API key is provided
# fail:
# msg: Please define an API key
# when: auth_key is not defined
- name: Test an API key is provided
fail:
msg: Please define an API key
when: auth_key is not defined
# - name: Use an invalid domain
# meraki_organization:
# auth_key: '{{ auth_key }}'
# host: marrrraki.com
# state: present
# org_name: IntTestOrg
# output_level: debug
# delegate_to: localhost
# register: invalid_domain
# ignore_errors: yes
- name: Use an invalid domain
meraki_organization:
auth_key: '{{ auth_key }}'
host: marrrraki.com
state: present
org_name: IntTestOrg
output_level: debug
delegate_to: localhost
register: invalid_domain
ignore_errors: yes
# - name: Disable HTTP
# meraki_organization:
# auth_key: '{{ auth_key }}'
# use_https: false
# state: query
# output_level: debug
# delegate_to: localhost
# register: http
# ignore_errors: yes
- name: Disable HTTP
meraki_organization:
auth_key: '{{ auth_key }}'
use_https: false
state: query
output_level: debug
delegate_to: localhost
register: http
ignore_errors: yes
# - name: Connection assertions
# assert:
# that:
# - '"Failed to connect to" in invalid_domain.msg'
# - '"http" in http.url'
- name: Connection assertions
assert:
that:
- '"Failed to connect to" in invalid_domain.msg'
- '"http" in http.url'
- name: Create network
meraki_network:
@ -54,9 +54,6 @@
delegate_to: localhost
register: query
- debug:
msg: '{{query}}'
- assert:
that:
- query.data|length == 1
@ -78,6 +75,9 @@
delegate_to: localhost
register: create_one
- debug:
var: create_one
- assert:
that:
- create_one.data|length == 2
@ -85,6 +85,7 @@
- create_one.data.0.protocol == 'tcp'
- create_one.data.0.policy == 'deny'
- create_one.changed == True
- create_one.data is defined
- name: Check for idempotency
meraki_mx_l3_firewall:
@ -109,6 +110,7 @@
- assert:
that:
- create_one_idempotent.changed == False
- create_one_idempotent.data is defined
- name: Create syslog in network
meraki_syslog:
@ -145,6 +147,10 @@
- debug:
msg: '{{default_syslog}}'
- assert:
that:
- default_syslog.data is defined
- name: Query firewall rules
meraki_mx_l3_firewall:
auth_key: '{{ auth_key }}'
@ -183,6 +189,10 @@
- debug:
msg: '{{disable_syslog}}'
- assert:
that:
- disable_syslog.data is defined
- name: Query firewall rules
meraki_mx_l3_firewall:
auth_key: '{{ auth_key }}'
@ -210,3 +220,11 @@
rules: []
delegate_to: localhost
register: delete_all
- name: Delete network
meraki_network:
auth_key: '{{ auth_key }}'
org_name: '{{test_org_name}}'
net_name: TestNetAppliance
state: absent
delegate_to: localhost

View file

@ -67,9 +67,6 @@
delegate_to: localhost
register: enable_vlan
- debug:
msg: '{{ enable_vlan }}'
- assert:
that:
- enable_vlan.data.enabled == True
@ -84,9 +81,13 @@
delegate_to: localhost
register: enable_vlan_idempotent
- debug:
var: enable_vlan_idempotent
- assert:
that:
- enable_vlan_idempotent is not changed
- enable_vlan_idempotent.data is defined
- name: Disable VLAN support on appliance network
meraki_network:
@ -98,9 +99,6 @@
delegate_to: localhost
register: disable_vlan
- debug:
msg: '{{ disable_vlan }}'
- assert:
that:
- disable_vlan.data.enabled == False
@ -118,6 +116,7 @@
- assert:
that:
- disable_vlan_idempotent is not changed
- disable_vlan_idempotent.data is defined
- name: Create network with type wireless
meraki_network:
@ -141,6 +140,10 @@
delegate_to: localhost
register: create_net_wireless_idempotent
- assert:
that:
- create_net_wireless_idempotent.data is defined
- name: Create network with type combined and disable my.meraki.com
meraki_network:
auth_key: '{{ auth_key }}'
@ -177,9 +180,6 @@
delegate_to: localhost
register: create_net_tag
- debug:
msg: '{{create_net_tag}}'
- name: Create network with two tags
meraki_network:
auth_key: '{{ auth_key }}'
@ -194,9 +194,6 @@
delegate_to: localhost
register: create_net_tags
- debug:
msg: '{{create_net_tags}}'
- name: Modify network
meraki_network:
auth_key: '{{ auth_key }}'
@ -227,6 +224,10 @@
delegate_to: localhost
register: create_net_modified_idempotent
- assert:
that:
- create_net_modified_idempotent.data is defined
- name: Present assertions
assert:
that:
@ -241,11 +242,13 @@
- '"IntTestNetworkSwitchOrgID" in create_net_switch_org_id.data.name'
- '"IntTestNetworkWireless" in create_net_wireless.data.name'
- create_net_wireless_idempotent.changed == False
- create_net_wireless_idempotent.data is defined
- '"first_tag" in create_net_tag.data.tags'
- '"second_tag" in create_net_tags.data.tags'
- '"third_tag" in create_net_modified.data.tags'
- create_net_modified.changed == True
- create_net_modified_idempotent.changed == False
- create_net_modified_idempotent.data is defined
- name: Query all networks
meraki_network:

View file

@ -91,6 +91,7 @@
- modify_org.changed == True
- 'modify_org.data.name == "IntTestOrgRenamed"'
- modify_org_idempotent.changed == False
- modify_org_idempotent.data is defined
- name: List all organizations
meraki_organization:

View file

@ -118,6 +118,7 @@
- assert:
that:
- snmp_idempotent.changed == False
- snmp_idempotent.data is defined
- name: Add peer IPs
meraki_snmp:

View file

@ -94,6 +94,7 @@
- assert:
that:
- enable_name_ssid_idempotent.changed == False
- enable_name_ssid_idempotent.data is defined
- name: Query one SSIDs
meraki_ssid:

View file

@ -106,6 +106,7 @@
- assert:
that:
- update_idempotent.changed == False
- update_idempotent.data is defined
- name: Update static route with fixed IP assignment and reservation
meraki_static_route:

View file

@ -218,6 +218,7 @@
- assert:
that:
- update_port_access_idempotent.changed == False
- update_port_access_idempotent.data is defined
- name: Configure trunk port
meraki_switchport:
@ -321,3 +322,4 @@
- assert:
that:
- update_trunk_idempotent.changed == False
- update_trunk_idempotent.data is defined

View file

@ -102,6 +102,7 @@
- assert:
that:
- create_server_idempotency.changed == False
- create_server_idempotency.data is defined
- name: Set multiple syslog servers # Broken
meraki_syslog:

View file

@ -165,6 +165,7 @@
- assert:
that:
- update_vlan_idempotent.changed == False
- update_vlan_idempotent.data is defined
- name: Add IP assignments and reserved IP ranges
meraki_vlan:
@ -262,6 +263,7 @@
- assert:
that:
- update_vlan_idempotent.changed == False
- update_vlan_idempotent.data is defined
- name: Update VLAN with list of DNS entries
meraki_vlan: