Coverage for plugins/modules/meraki_syslog.py : 67%

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) 2018, 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_syslog short_description: Manage syslog server settings in the Meraki cloud. version_added: "2.8" description: - Allows for creation and management of Syslog servers within Meraki. notes: - Changes to existing syslog servers replaces existing configuration. If you need to add to an existing configuration set state to query to gather the existing configuration and then modify or add. options: auth_key: description: - Authentication key provided by the dashboard. Required if environmental variable MERAKI_KEY is not set. type: str state: description: - Query or edit syslog servers - To delete a syslog server, do not include server in list of servers choices: [present, query] default: present type: str net_name: description: - Name of a network. aliases: [name, network] type: str net_id: description: - ID number of a network. type: str servers: description: - List of syslog server settings type: list suboptions: host: description: - IP address or hostname of Syslog server. type: str port: description: - Port number Syslog server is listening on. default: "514" type: int roles: description: - List of applicable Syslog server roles. choices: ['Wireless Event log', 'Appliance event log', 'Switch event log', 'Air Marshal events', 'Flows', 'URLs', 'IDS alerts', 'Security events'] type: list
author: - Kevin Breit (@kbreit) extends_documentation_fragment: meraki '''
- name: Query syslog configurations on network named MyNet in the YourOrg organization meraki_syslog: auth_key: abc12345 status: query org_name: YourOrg net_name: MyNet delegate_to: localhost
- name: Add single syslog server with Appliance event log role meraki_syslog: auth_key: abc12345 status: query org_name: YourOrg net_name: MyNet servers: - host: 192.0.1.2 port: 514 roles: - Appliance event log delegate_to: localhost
- name: Add multiple syslog servers meraki_syslog: auth_key: abc12345 status: query org_name: YourOrg net_name: MyNet servers: - host: 192.0.1.2 port: 514 roles: - Appliance event log - host: 192.0.1.3 port: 514 roles: - Appliance event log - Flows delegate_to: localhost '''
data: description: Information about the created or manipulated object. returned: info type: complex contains: host: description: Hostname or IP address of syslog server. returned: success type: str sample: 192.0.1.1 port: description: Port number for syslog communication. returned: success type: str sample: 443 roles: description: List of roles assigned to syslog server. returned: success type: list sample: "Wireless event log, URLs" '''
# define the available arguments/parameters that a user can pass to # the module
port=dict(type='int', default="514"), roles=dict(type='list', choices=['Wireless Event log', 'Appliance event log', 'Switch event log', 'Air Marshal events', 'Flows', 'URLs', 'IDS alerts', 'Security events', ]), )
servers=dict(type='list', element='dict', options=server_arg_spec), state=dict(type='str', choices=['present', 'query'], default='present'), net_name=dict(type='str', aliases=['name', 'network']), )
# 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 supports_check_mode=True, )
meraki.fail_json(msg='org_name or org_id parameters are required') meraki.fail_json(msg='net_name or net_id is required for present or absent states') meraki.fail_json(msg='net_name and net_id are mutually exclusive')
# 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
# manipulate or modify the state as needed (this is going to be the # part where your module will do what it needs to do)
path = meraki.construct_path('query_update', net_id=net_id) r = meraki.request(path, method='GET') if meraki.status == 200: meraki.result['data'] = r # Construct payload
# Convert port numbers to string for idempotency checks
meraki.generate_diff(original, payload) original.update(payload) meraki.result['data'] = original meraki.result['changed'] = True meraki.exit_json(**meraki.result) else: if meraki.module.check_mode is True: meraki.result['data'] = original meraki.exit_json(**meraki.result) meraki.result['data'] = original
# in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results
|