Coverage for plugins/modules/meraki_management_interface.py : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # -*- coding: utf-8 -*-
# Copyright: (c) 2019, Kevin Breit (@kbreit) <kevin.breit@kevinbreit.net> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' }
--- module: meraki_management_interface short_description: Configure Meraki management interfaces version_added: "2.10" description: - Allows for configuration of management interfaces on Meraki devices. notes: - C(WAN2) parameter is only valid for MX appliances. - C(enabled) can only be set to C(not configured) for MS switches. options: state: description: - Specifies whether configuration template information should be queried, modified, or deleted. choices: ['absent', 'query', 'present'] default: query type: str org_name: description: - Name of organization containing the configuration template. type: str org_id: description: - ID of organization associated to a configuration template. type: str net_name: description: - Name of the network to bind or unbind configuration template to. type: str net_id: description: - ID of the network to bind or unbind configuration template to. type: str serial: description: - serial number of the device to configure. type: str wan1: description: - Management interface details for management interface. aliases: [mgmt1] type: dict suboptions: wan_enabled: description: - States whether the management interface is enabled. type: str choices: [disabled, enabled, not configured] using_static_ip: description: - Configures the interface to use static IP or DHCP. type: bool static_ip: description: - IP address assigned to Management interface. - Valid only if C(using_static_ip) is C(True). type: str static_gateway_ip: description: - IP address for default gateway. - Valid only if C(using_static_ip) is C(True). type: str static_subnet_mask: description: - Netmask for static IP address. - Valid only if C(using_static_ip) is C(True). type: str static_dns: description: - DNS servers to use. - Allows for a maximum of 2 addresses. type: list vlan: description: - VLAN number to use for the management network. type: int wan2: description: - Management interface details for management interface. type: dict aliases: [mgmt2] suboptions: wan_enabled: description: - States whether the management interface is enabled. type: str choices: [disabled, enabled, not configured] using_static_ip: description: - Configures the interface to use static IP or DHCP. type: bool static_ip: description: - IP address assigned to Management interface. - Valid only if C(using_static_ip) is C(True). type: str static_gateway_ip: description: - IP address for default gateway. - Valid only if C(using_static_ip) is C(True). type: str static_subnet_mask: description: - Netmask for static IP address. - Valid only if C(using_static_ip) is C(True). type: str static_dns: description: - DNS servers to use. - Allows for a maximum of 2 addresses. type: list vlan: description: - VLAN number to use for the management network. type: int
author: - Kevin Breit (@kbreit) extends_documentation_fragment: meraki '''
- name: Set WAN2 as static IP meraki_management_interface: auth_key: abc123 state: present org_name: YourOrg net_id: YourNetId serial: AAAA-BBBB-CCCC wan2: wan_enabled: enabled using_static_ip: yes static_ip: 192.168.16.195 static_gateway_ip: 192.168.16.1 static_subnet_mask: 255.255.255.0 static_dns: - 1.1.1.1 vlan: 1 delegate_to: localhost
- name: Query management information meraki_management_interface: auth_key: abc123 state: query org_name: YourOrg net_id: YourNetId serial: AAAA-BBBB-CCCC delegate_to: localhost '''
data: description: Information about queried object. returned: success type: complex contains: wan1: description: Management configuration for WAN1 interface returned: success type: complex contains: wan_enabled: description: Enabled state of interface returned: success type: string sample: enabled using_static_ip: description: Boolean value of whether static IP assignment is used on interface returned: success type: bool sample: True static_ip: description: Assigned static IP returned: only if static IP assignment is used type: string sample: 192.0.1.2 static_gateway_ip: description: Assigned static gateway IP returned: only if static IP assignment is used type: string sample: 192.0.1.1 static_subnet_mask: description: Assigned netmask for static IP returned: only if static IP assignment is used type: string sample: 255.255.255.0 static_dns: description: List of DNS IP addresses returned: only if static IP assignment is used type: list sample: ["1.1.1.1"] vlan: description: VLAN tag id of management VLAN returned: success type: int sample: 2 wan2: description: Management configuration for WAN1 interface returned: success type: complex contains: wan_enabled: description: Enabled state of interface returned: success type: string sample: enabled using_static_ip: description: Boolean value of whether static IP assignment is used on interface returned: success type: bool sample: True static_ip: description: Assigned static IP returned: only if static IP assignment is used type: string sample: 192.0.1.2 static_gateway_ip: description: Assigned static gateway IP returned: only if static IP assignment is used type: string sample: 192.0.1.1 static_subnet_mask: description: Assigned netmask for static IP returned: only if static IP assignment is used type: string sample: 255.255.255.0 static_dns: description: List of DNS IP addresses returned: only if static IP assignment is used type: list sample: ["1.1.1.1"] vlan: description: VLAN tag id of management VLAN returned: success type: int sample: 2 '''
# define the available arguments/parameters that a user can pass to # the module
using_static_ip=dict(type='bool'), static_ip=dict(type='str'), static_gateway_ip=dict(type='str'), static_subnet_mask=dict(type='str'), static_dns=dict(type='list', element='str'), vlan=dict(type='int'), )
net_name=dict(type='str'), net_id=dict(type='str'), serial=dict(type='str', required=True), wan1=dict(type='dict', default=None, options=int_arg_spec, aliases=['mgmt1']), wan2=dict(type='dict', default=None, options=int_arg_spec, aliases=['mgmt2']), )
# the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) meraki = MerakiModule(module, function='management_interface')
query_urls = {'management_interface': '/networks/{net_id}/devices/{serial}/managementInterfaceSettings'}
meraki.url_catalog['get_one'].update(query_urls)
if meraki.params['net_id'] and meraki.params['net_name']: interfaces = ('wan1', 'wan2') if meraki.params[interface]['using_static_ip'] is True: meraki.fail_json("Maximum number of static DNS addresses is 2.")
payload = dict()
if meraki.params['state'] == 'present': 'usingStaticIp': meraki.params[interface]['using_static_ip'], } wan_int['vlan'] = meraki.params[interface]['vlan'] wan_int['staticIp'] = meraki.params[interface]['static_ip']
# manipulate or modify the state as needed (this is going to be the # part where your module will do what it needs to do)
if meraki.params['state'] == 'query': path = meraki.construct_path('get_one', net_id=net_id, custom={'serial': meraki.params['serial']}) response = meraki.request(path, method='GET') # meraki.fail_json(path) original = meraki.request(path, method='GET') if meraki.is_update_required(original, payload): if meraki.check_mode is True: 'after': diff[1]} 'after': diff[1]} else:
# in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results
|