From 7b07c9b22055f086253364d289de5bf4dcfe526a Mon Sep 17 00:00:00 2001 From: Kevin Breit Date: Mon, 9 Jul 2018 04:21:34 -0500 Subject: [PATCH] meraki_network - Add support for disableMyMerakiCom (#42418) * Add support for disable_my_meraki parameter - Meraki added support for the disabling access to Meraki websites on devices. This module now supports this. - I haven't tested this as it was developed on an iPad. It will work before submitting PR. - Rework of payload generation code is required or at least recommended. - Integration tests need to be developed. * Added support for disableMyMerakiCom parameter * - Remove proposed functions as it isn't required for updates - Add integration tests - Still pending a case response from Meraki since I can't seem to set disableMyMerakiCom to false after it's true * Fixed word wrap problem * Add version_added to disable_my_meraki --- .../modules/network/meraki/meraki_network.py | 32 ++++++++++--------- .../targets/meraki_network/tasks/main.yml | 16 +++++++++- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/ansible/modules/network/meraki/meraki_network.py b/lib/ansible/modules/network/meraki/meraki_network.py index c17106ba9c5..34b408f66d1 100644 --- a/lib/ansible/modules/network/meraki/meraki_network.py +++ b/lib/ansible/modules/network/meraki/meraki_network.py @@ -56,6 +56,12 @@ options: description: - Timezone associated to network. - See U(https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for a list of valid timezones. + disable_my_meraki: + description: > + - Disables the local device status pages (U[my.meraki.com](my.meraki.com), U[ap.meraki.com](ap.meraki.com), U[switch.meraki.com](switch.meraki.com), + U[wired.meraki.com](wired.meraki.com)) + type: bool + version_added: '2.7' author: - Kevin Breit (@kbreit) @@ -85,6 +91,7 @@ EXAMPLES = r''' type: switch timezone: America/Chicago tags: production, chicago + delegate_to: localhost ''' RETURN = r''' @@ -170,6 +177,7 @@ def main(): timezone=dict(type='str'), net_name=dict(type='str', aliases=['name', 'network']), state=dict(type='str', choices=['present', 'query', 'absent'], default='present'), + disable_my_meraki=dict(type='bool'), ) # the AnsibleModule object will be our abstraction working with Ansible @@ -207,15 +215,19 @@ def main(): # Construct payload if meraki.params['state'] == 'present': - payload = {'name': meraki.params['net_name'], - 'type': meraki.params['type'], - } + payload = dict() + if meraki.params['net_name']: + payload['name'] = meraki.params['net_name'] + if meraki.params['type']: + payload['type'] = meraki.params['type'] + if meraki.params['type'] == 'combined': + payload['type'] = 'switch wireless appliance' if meraki.params['tags']: payload['tags'] = construct_tags(meraki.params['tags']) if meraki.params['timezone']: payload['timeZone'] = meraki.params['timezone'] - if meraki.params['type'] == 'combined': - payload['type'] = 'switch wireless appliance' + if meraki.params['disable_my_meraki']: + payload['disableMyMerakiCom'] = meraki.params['disable_my_meraki'] # manipulate or modify the state as needed (this is going to be the # part where your module will do what it needs to do) @@ -248,16 +260,6 @@ def main(): meraki.result['changed'] = True else: net = meraki.get_net(meraki.params['org_name'], meraki.params['net_name'], data=nets) - proposed = payload - if meraki.params['timezone']: - proposed['timeZone'] = meraki.params['timezone'] - else: - proposed['timeZone'] = 'America/Los_Angeles' - if not meraki.params['tags']: - proposed['tags'] = None - if not proposed['type']: - proposed['type'] = net['type'] - if meraki.is_update_required(net, payload): path = meraki.construct_path('update', net_id=meraki.get_net_id(net_name=meraki.params['net_name'], data=nets) diff --git a/test/integration/targets/meraki_network/tasks/main.yml b/test/integration/targets/meraki_network/tasks/main.yml index 0ece172e134..668f65c3955 100644 --- a/test/integration/targets/meraki_network/tasks/main.yml +++ b/test/integration/targets/meraki_network/tasks/main.yml @@ -79,7 +79,7 @@ delegate_to: localhost register: create_net_wireless_idempotent - - name: Create network with type combined + - name: Create network with type combined and disable my.meraki.com meraki_network: auth_key: '{{ auth_key }}' state: present @@ -87,8 +87,19 @@ net_name: IntTestNetworkCombined type: combined timezone: America/Chicago + disable_my_meraki: yes delegate_to: localhost register: create_net_combined + + - name: Reenable my.meraki.com + meraki_network: + auth_key: '{{ auth_key }}' + state: present + org_name: '{{test_org_name}}' + net_name: IntTestNetworkCombined + disable_my_meraki: no + delegate_to: localhost + register: enable_meraki_com - name: Create network with one tag meraki_network: @@ -148,6 +159,9 @@ assert: that: - create_net_no_type.status == 500 + - create_net_combined.data.type == 'combined' + - create_net_combined.data.disableMyMerakiCom == True + - enable_meraki_com.data.disableMyMerakiCom == False - '"org_name or org_id parameters are required" in create_net_no_org.msg' - '"IntTestNetworkAppliance" in create_net_appliance_no_tz.data.name' - create_net_appliance_no_tz.changed == True