Repository: ansible/ansible

Issue:
meraki_network - Add support for disableMyMerakiCom
##### SUMMARY
Meraki recently added support for a new parameter in the API, `disableMyMerakiCom`. To quote Meraki "Disables the local device status pages (my.meraki.com, ap.meraki.com, switch.meraki.com, wired.meraki.com)". The `meraki_network` module should be able to set this properly.

##### ISSUE TYPE
 - Feature Idea

##### COMPONENT NAME
meraki_network

##### ANSIBLE VERSION
```
ansible 2.7.0.dev0 (devel 52e7946de5) last updated 2018/07/01 19:13:09 (GMT -500)
  config file = None
  configured module search path = ['/Users/kbreit/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/kbreit/Documents/Programming/ansible/lib/ansible
  executable location = /Users/kbreit/Documents/Programming/ansible/bin/ansible
  python version = 3.5.4 (default, Feb 25 2018, 14:56:02) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

```


Discussion:
Files identified in the description:
* [lib/ansible/modules/network/meraki/meraki_network.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/meraki/meraki_network.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @dagwieers
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/meraki/meraki_network.py b/lib/ansible/modules/network/meraki/meraki_network.py
--- a/lib/ansible/modules/network/meraki/meraki_network.py
+++ b/lib/ansible/modules/network/meraki/meraki_network.py
@@ -56,6 +56,12 @@
         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 @@
     type: switch
     timezone: America/Chicago
     tags: production, chicago
+  delegate_to: localhost
 '''
 
 RETURN = r'''
@@ -145,6 +152,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
@@ -182,15 +190,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)
@@ -223,16 +235,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)


Test patch:
diff --git a/test/integration/targets/meraki_network/tasks/main.yml b/test/integration/targets/meraki_network/tasks/main.yml
--- 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