mirror of
https://github.com/zahodi/ansible-mikrotik.git
synced 2025-07-25 13:25:03 +02:00
add ovpn-client to the interfaces module
add check mode to interface_wireless module up date checks
This commit is contained in:
parent
220f44766b
commit
297f3228bc
3 changed files with 153 additions and 113 deletions
|
@ -50,70 +50,69 @@ EXAMPLES = '''
|
|||
|
||||
'''
|
||||
|
||||
from mt_common import clean_params, MikrotikIdempotent
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from mt_common import clean_params, MikrotikIdempotent
|
||||
|
||||
|
||||
def main():
|
||||
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 = ['security-profiles'],
|
||||
type = 'str'
|
||||
),
|
||||
state = dict(
|
||||
required = False,
|
||||
choices = ['present', 'absent'],
|
||||
type = 'str'
|
||||
),
|
||||
)
|
||||
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 = ['security-profiles'],
|
||||
type = 'str'
|
||||
),
|
||||
state = dict(
|
||||
required = False,
|
||||
choices = ['present', 'absent'],
|
||||
type = 'str'
|
||||
),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
idempotent_parameter = None
|
||||
params = module.params
|
||||
|
||||
idempotent_parameter = 'name'
|
||||
|
||||
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 = '/interface/wireless/' + str(params['parameter']),
|
||||
check_mode = module.check_mode
|
||||
)
|
||||
|
||||
mt_obj.sync_state()
|
||||
|
||||
if mt_obj.failed:
|
||||
module.fail_json(
|
||||
msg = mt_obj.failed_msg
|
||||
)
|
||||
elif mt_obj.changed:
|
||||
module.exit_json(
|
||||
failed=False,
|
||||
changed=True,
|
||||
msg=mt_obj.changed_msg,
|
||||
diff={ "prepared": {
|
||||
"old": mt_obj.old_params,
|
||||
"new": mt_obj.new_params,
|
||||
}},
|
||||
)
|
||||
|
||||
idempotent_parameter = None
|
||||
params = module.params
|
||||
|
||||
idempotent_parameter = 'name'
|
||||
|
||||
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 = '/interface/wireless/' + str(params['parameter']),
|
||||
|
||||
else:
|
||||
module.exit_json(
|
||||
failed=False,
|
||||
changed=False,
|
||||
msg=params['settings'],
|
||||
)
|
||||
|
||||
mt_obj.sync_state()
|
||||
|
||||
if mt_obj.failed:
|
||||
module.fail_json(
|
||||
msg = mt_obj.failed_msg
|
||||
)
|
||||
elif mt_obj.changed:
|
||||
module.exit_json(
|
||||
failed=False,
|
||||
changed=True,
|
||||
msg=mt_obj.changed_msg,
|
||||
diff={ "prepared": {
|
||||
"old": mt_obj.old_params,
|
||||
"new": mt_obj.new_params,
|
||||
}},
|
||||
)
|
||||
else:
|
||||
module.exit_json(
|
||||
failed=False,
|
||||
changed=False,
|
||||
#msg='',
|
||||
msg=params['settings'],
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue