diff options
author | Kevin Breit <kevin.breit@kevinbreit.net> | 2019-06-05 09:23:54 -0500 |
---|---|---|
committer | Nathaniel Case <ncase@redhat.com> | 2019-06-05 10:23:54 -0400 |
commit | 6da2d405000b65b1212da8d07b55228a8266287b (patch) | |
tree | db4c29bf6b78dcfa6f309d7e7c94d1bd901d1338 /lib/ansible/modules/network/meraki/meraki_admin.py | |
parent | 30aeab470975be32b635f4ad5dd6dcf5efe4b425 (diff) | |
download | ansible-6da2d405000b65b1212da8d07b55228a8266287b.tar.gz |
meraki_admin - Enable check mode (#54499)
* Add support for check mode
* Add changelog fragment
* Add diff support
- Fix a few changed status
- Removed auth_key check since that's done in module_utils now
Diffstat (limited to 'lib/ansible/modules/network/meraki/meraki_admin.py')
-rw-r--r-- | lib/ansible/modules/network/meraki/meraki_admin.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/ansible/modules/network/meraki/meraki_admin.py b/lib/ansible/modules/network/meraki/meraki_admin.py index b1db3b58a8..7f92ae3f47 100644 --- a/lib/ansible/modules/network/meraki/meraki_admin.py +++ b/lib/ansible/modules/network/meraki/meraki_admin.py @@ -255,6 +255,7 @@ import os from ansible.module_utils.basic import AnsibleModule, json, env_fallback from ansible.module_utils.urls import fetch_url from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import recursive_diff from ansible.module_utils.network.meraki.meraki import MerakiModule, meraki_argument_spec @@ -337,9 +338,12 @@ def create_admin(meraki, org_id, name, email): if meraki.params['networks'] is not None: nets = meraki.get_nets(org_id=org_id) networks = network_factory(meraki, meraki.params['networks'], nets) - # meraki.fail_json(msg=str(type(networks)), data=networks) payload['networks'] = networks if is_admin_existing is None: # Create new admin + if meraki.module.check_mode is True: + meraki.result['data'] = payload + meraki.result['changed'] = True + meraki.exit_json(**meraki.result) path = meraki.construct_path('create', function='admin', org_id=org_id) r = meraki.request(path, method='POST', @@ -354,6 +358,15 @@ 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: + if meraki.module.check_mode is True: + diff = recursive_diff(is_admin_existing, payload) + is_admin_existing.update(payload) + meraki.result['diff'] = {'before': diff[0], + 'after': diff[1], + } + meraki.result['changed'] = True + meraki.result['data'] = payload + meraki.exit_json(**meraki.result) path = meraki.construct_path('update', function='admin', org_id=org_id) + is_admin_existing['id'] r = meraki.request(path, method='PUT', @@ -364,6 +377,9 @@ def create_admin(meraki, org_id, name, email): return r else: meraki.result['data'] = is_admin_existing + if meraki.module.check_mode is True: + meraki.result['data'] = payload + meraki.exit_json(**meraki.result) return -1 @@ -395,7 +411,7 @@ def main(): # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, - supports_check_mode=False, + supports_check_mode=True, ) meraki = MerakiModule(module, function='admin') @@ -421,16 +437,11 @@ def main(): except KeyError: pass - if meraki.params['auth_key'] is None: - module.fail_json(msg='Meraki Dashboard API key not set') - payload = None # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications - if module.check_mode: - return result # execute checks for argument completeness if meraki.params['state'] == 'query': @@ -468,6 +479,10 @@ def main(): if r != -1: meraki.result['data'] = r elif meraki.params['state'] == 'absent': + if meraki.module.check_mode is True: + meraki.result['data'] = {} + meraki.result['changed'] = True + meraki.exit_json(**meraki.result) admin_id = get_admin_id(meraki, get_admins(meraki, org_id), email=meraki.params['email'] |