2017-05-25 16:30:10 -07:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: mt_radius
|
|
|
|
author:
|
|
|
|
- "Valentin Gurmeza"
|
|
|
|
- "Shaun Smiley"
|
|
|
|
version_added: "2.3"
|
|
|
|
short_description: Manage mikrotik radius client
|
|
|
|
requirements:
|
|
|
|
- mt_api
|
|
|
|
description:
|
|
|
|
- Add or remove a radius client
|
|
|
|
options:
|
|
|
|
hostname:
|
|
|
|
description:
|
|
|
|
- hotstname of mikrotik router
|
|
|
|
username:
|
|
|
|
description:
|
|
|
|
- username used to connect to mikrotik router
|
|
|
|
password:
|
|
|
|
description:
|
|
|
|
- password used for authentication to mikrotik router
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- client present or absent
|
2017-06-14 18:15:48 -07:00
|
|
|
required: False
|
2017-05-25 16:30:10 -07:00
|
|
|
choices:
|
|
|
|
- present
|
|
|
|
- absent
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
# Add a new radius entry
|
2017-06-16 10:39:32 -07:00
|
|
|
- mt_radius:
|
2017-06-14 18:15:48 -07:00
|
|
|
hostname: "{{ inventory_hostname }}"
|
|
|
|
username: "{{ mt_user }}"
|
|
|
|
password: "{{ mt_pass }}"
|
2017-05-25 16:30:10 -07:00
|
|
|
state: present
|
2017-06-14 18:15:48 -07:00
|
|
|
parameter: radius
|
|
|
|
settings:
|
|
|
|
address: 192.168.230.1
|
|
|
|
comment: ansible_test
|
|
|
|
timeout: '2s500ms'
|
|
|
|
secret: 'password'
|
|
|
|
service:
|
|
|
|
- login
|
|
|
|
- hotspot
|
|
|
|
- wireless
|
2017-05-25 16:30:10 -07:00
|
|
|
'''
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2017-06-14 18:15:48 -07:00
|
|
|
from mt_common import MikrotikIdempotent
|
2017-05-25 16:30:10 -07:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-06-14 18:15:48 -07:00
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
hostname = dict(required=True),
|
|
|
|
username = dict(required=True),
|
|
|
|
password = dict(required=True),
|
|
|
|
settings = dict(required=False, type='dict'),
|
|
|
|
parameter = dict(
|
|
|
|
required = True,
|
|
|
|
choices = ['radius', 'incoming'],
|
|
|
|
type = 'str'
|
|
|
|
),
|
|
|
|
state = dict(
|
|
|
|
required = False,
|
|
|
|
choices = ['present', 'absent'],
|
|
|
|
type = 'str'
|
|
|
|
),
|
|
|
|
),
|
2017-06-05 16:10:27 -07:00
|
|
|
supports_check_mode=True
|
2017-05-25 16:30:10 -07:00
|
|
|
)
|
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
idempotent_parameter = None
|
|
|
|
params = module.params
|
2017-05-25 16:30:10 -07:00
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
if params['parameter'] == 'radius':
|
|
|
|
idempotent_parameter = 'comment'
|
|
|
|
params['parameter'] = "/radius"
|
2017-05-25 16:30:10 -07:00
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
if params['parameter'] == 'incoming':
|
|
|
|
params['parameter'] = "/radius/incoming"
|
2017-05-25 16:30:10 -07:00
|
|
|
|
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
mt_obj = MikrotikIdempotent(
|
|
|
|
hostname = params['hostname'],
|
|
|
|
username = params['username'],
|
|
|
|
password = params['password'],
|
|
|
|
state = params['state'],
|
|
|
|
desired_params = params['settings'],
|
|
|
|
idempotent_param = idempotent_parameter,
|
|
|
|
api_path = str(params['parameter']),
|
|
|
|
check_mode = module.check_mode,
|
2017-05-25 16:30:10 -07:00
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
)
|
2017-05-25 16:30:10 -07:00
|
|
|
|
2017-06-14 18:15:48 -07:00
|
|
|
mt_obj.sync_state()
|
|
|
|
|
|
|
|
if mt_obj.failed:
|
|
|
|
module.fail_json(
|
|
|
|
msg = mt_obj.failed_msg
|
|
|
|
)
|
|
|
|
elif mt_obj.changed:
|
2017-05-25 16:30:10 -07:00
|
|
|
module.exit_json(
|
|
|
|
failed=False,
|
|
|
|
changed=True,
|
2017-06-14 18:15:48 -07:00
|
|
|
msg=mt_obj.changed_msg,
|
|
|
|
diff={ "prepared": {
|
|
|
|
"old": mt_obj.old_params,
|
|
|
|
"new": mt_obj.new_params,
|
|
|
|
}},
|
2017-05-25 16:30:10 -07:00
|
|
|
)
|
2017-06-14 18:15:48 -07:00
|
|
|
else:
|
2017-05-25 16:30:10 -07:00
|
|
|
module.exit_json(
|
|
|
|
failed=False,
|
|
|
|
changed=False,
|
2017-06-14 18:15:48 -07:00
|
|
|
#msg='',
|
|
|
|
msg=params['settings'],
|
2017-05-25 16:30:10 -07:00
|
|
|
)
|
2017-06-14 18:15:48 -07:00
|
|
|
|
2017-05-25 16:30:10 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|