Skip to content

Commit

Permalink
Merge pull request #208 from kbreit/bugfix/management-error
Browse files Browse the repository at this point in the history
meraki_management_interface - Fix crash on non-MX devices
  • Loading branch information
kbreit authored Nov 2, 2020
2 parents 3b3d0fb + e623289 commit e534507
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/management_ms_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- meraki_management_interface - Fix crash when modifying a non-MX management interface.
27 changes: 21 additions & 6 deletions plugins/modules/meraki_management_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
short_description: Configure Meraki management interfaces
version_added: "1.1.0"
description:
- Allows for configuration of management interfaces on Meraki devices.
- Allows for configuration of management interfaces on Meraki MX, MS, and MR devices.
notes:
- C(WAN2) parameter is only valid for MX appliances.
- C(enabled) can only be set to C(not configured) for MS switches.
- C(wan_enabled) should not be provided for non-MX devies.
options:
state:
description:
Expand Down Expand Up @@ -60,6 +60,7 @@
wan_enabled:
description:
- States whether the management interface is enabled.
- Only valid for MX devices.
type: str
choices: [disabled, enabled, not configured]
using_static_ip:
Expand Down Expand Up @@ -100,6 +101,7 @@
wan_enabled:
description:
- States whether the management interface is enabled.
- Only valid for MX devices.
type: str
choices: [disabled, enabled, not configured]
using_static_ip:
Expand Down Expand Up @@ -311,9 +313,11 @@ def main():
interfaces = ('wan1', 'wan2')
for interface in interfaces:
if meraki.params[interface] is not None:
wan_int = {'wanEnabled': meraki.params[interface]['wan_enabled'],
'usingStaticIp': meraki.params[interface]['using_static_ip'],
}
wan_int = dict()
if meraki.params[interface]['wan_enabled'] is not None:
wan_int['wanEnabled'] = meraki.params[interface]['wan_enabled']
if meraki.params[interface]['using_static_ip'] is not None:
wan_int['usingStaticIp'] = meraki.params[interface]['using_static_ip']
if meraki.params[interface]['vlan'] is not None:
wan_int['vlan'] = meraki.params[interface]['vlan']
if meraki.params[interface]['using_static_ip'] is True:
Expand Down Expand Up @@ -341,7 +345,18 @@ def main():
elif meraki.params['state'] == 'present':
path = meraki.construct_path('get_one', custom={'serial': meraki.params['serial']})
original = meraki.request(path, method='GET')
if meraki.is_update_required(original, payload):
update_required = False
if 'wan1' in original:
if 'wanEnabled' in original['wan1']:
update_required = meraki.is_update_required(original, payload)
else:
update_required = meraki.is_update_required(original, payload, optional_ignore=['wanEnabled'])
if 'wan2' in original and update_required is False:
if 'wanEnabled' in original['wan2']:
update_required = meraki.is_update_required(original, payload)
else:
update_required = meraki.is_update_required(original, payload, optional_ignore=['wanEnabled'])
if update_required is True:
if meraki.check_mode is True:
diff = recursive_diff(original, payload)
original.update(payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- set_fact:
net_name: TestNet - Appliance

- name: Create test network
- name: 'Create test network {{net_name}}'
meraki_network:
auth_key: '{{auth_key}}'
state: present
Expand All @@ -25,6 +25,83 @@
- set_fact:
net_id: '{{net.data.id}}'

- name: Test providing wan_enabled to an MS network
meraki_management_interface:
auth_key: '{{auth_key}}'
state: present
org_id: '{{test_org_id}}'
net_id: '{{test_switch_net_name}}'
serial: '{{serial_switch}}'
wan1:
wan_enabled: enabled
using_static_ip: false
delegate_to: localhost
register: ms_not_configured

- debug:
var: ms_not_configured

- assert:
that:
- ms_not_configured.data is defined

- name: Set management interface on switch
meraki_management_interface:
auth_key: '{{auth_key}}'
state: present
org_id: '{{test_org_id}}'
net_id: '{{test_switch_net_name}}'
serial: '{{serial_switch}}'
wan1:
using_static_ip: no
vlan: 3
delegate_to: localhost
register: set_switch_mgmt

- debug:
var: set_switch_mgmt

- assert:
that:
- set_switch_mgmt.data is defined

- name: Query non-MX network
meraki_management_interface:
auth_key: '{{auth_key}}'
state: query
org_id: '{{test_org_id}}'
net_id: '{{test_switch_net_name}}'
serial: '{{serial_switch}}'
delegate_to: localhost
register: non_mx_network

- debug:
var: non_mx_network

- assert:
that:
- non_mx_network.data is defined

- name: Reset management interface on switch
meraki_management_interface:
auth_key: '{{auth_key}}'
state: present
org_id: '{{test_org_id}}'
net_id: '{{test_switch_net_name}}'
serial: '{{serial_switch}}'
wan1:
using_static_ip: no
vlan: 1
delegate_to: localhost
register: reset_switch_mgmt

- debug:
var: reset_switch_mgmt

- assert:
that:
- reset_switch_mgmt.data is defined

- name: Set WAN1 as DHCP in check mode
meraki_management_interface:
auth_key: '{{auth_key}}'
Expand Down

0 comments on commit e534507

Please sign in to comment.