mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07: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:
parent
a3c3fd91f8
commit
2a187f362a
29 changed files with 167 additions and 96 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue