mirror of
https://github.com/zahodi/ansible-mikrotik.git
synced 2025-08-01 08:34:28 +02:00
add check mode to tests.yml
This commit is contained in:
parent
8ddf2e67d9
commit
fcd02f6384
2 changed files with 75 additions and 59 deletions
|
@ -53,69 +53,69 @@ from mt_common import clean_params, MikrotikIdempotent
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
hostname = dict(required=True),
|
hostname = dict(required=True),
|
||||||
username = dict(required=True),
|
username = dict(required=True),
|
||||||
password = dict(required=True),
|
password = dict(required=True),
|
||||||
settings = dict(required=False, type='dict'),
|
settings = dict(required=False, type='dict'),
|
||||||
parameter = dict(
|
parameter = dict(
|
||||||
required = True,
|
required = True,
|
||||||
choices = ['e-mail', 'netwatch'],
|
choices = ['e-mail', 'netwatch'],
|
||||||
type = 'str'
|
type = 'str'
|
||||||
),
|
),
|
||||||
state = dict(
|
state = dict(
|
||||||
required = False,
|
required = False,
|
||||||
choices = ['present', 'absent'],
|
choices = ['present', 'absent'],
|
||||||
type = 'str'
|
type = 'str'
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
)
|
supports_check_mode=True
|
||||||
|
)
|
||||||
|
|
||||||
idempotent_parameter = None
|
idempotent_parameter = None
|
||||||
params = module.params
|
params = module.params
|
||||||
|
|
||||||
if params['parameter'] == 'netwatch':
|
if params['parameter'] == 'netwatch':
|
||||||
idempotent_parameter = 'host'
|
idempotent_parameter = 'host'
|
||||||
|
|
||||||
# clean_params(params['settings'])
|
# clean_params(params['settings'])
|
||||||
|
|
||||||
mt_obj = MikrotikIdempotent(
|
mt_obj = MikrotikIdempotent(
|
||||||
hostname = params['hostname'],
|
hostname = params['hostname'],
|
||||||
username = params['username'],
|
username = params['username'],
|
||||||
password = params['password'],
|
password = params['password'],
|
||||||
state = params['state'],
|
state = params['state'],
|
||||||
desired_params = params['settings'],
|
desired_params = params['settings'],
|
||||||
idempotent_param = idempotent_parameter,
|
idempotent_param = idempotent_parameter,
|
||||||
api_path = '/tool/' + str(params['parameter']),
|
api_path = '/tool/' + 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:
|
||||||
mt_obj.sync_state()
|
module.exit_json(
|
||||||
|
failed=False,
|
||||||
if mt_obj.failed:
|
changed=True,
|
||||||
module.fail_json(
|
msg=mt_obj.changed_msg,
|
||||||
msg = mt_obj.failed_msg
|
diff={"prepared": {
|
||||||
)
|
"old": mt_obj.old_params,
|
||||||
elif mt_obj.changed:
|
"new": mt_obj.new_params,
|
||||||
module.exit_json(
|
}},
|
||||||
failed=False,
|
)
|
||||||
changed=True,
|
else:
|
||||||
msg=mt_obj.changed_msg,
|
module.exit_json(
|
||||||
diff={ "prepared": {
|
failed=False,
|
||||||
"old": mt_obj.old_params,
|
changed=False,
|
||||||
"new": mt_obj.new_params,
|
msg=params['settings'],
|
||||||
}},
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
module.exit_json(
|
|
||||||
failed=False,
|
|
||||||
changed=False,
|
|
||||||
#msg='',
|
|
||||||
msg=params['settings'],
|
|
||||||
)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1515,7 +1515,11 @@
|
||||||
address: 192.168.1.3
|
address: 192.168.1.3
|
||||||
from: email@localhost.com
|
from: email@localhost.com
|
||||||
register: email_edit
|
register: email_edit
|
||||||
failed_when: not ( email_edit | changed )
|
failed_when: (
|
||||||
|
not ansible_check_mode
|
||||||
|
) and (
|
||||||
|
not ( email_edit | changed )
|
||||||
|
)
|
||||||
|
|
||||||
- name: add netwatch item
|
- name: add netwatch item
|
||||||
mt_tool:
|
mt_tool:
|
||||||
|
@ -1539,7 +1543,11 @@
|
||||||
host: '192.168.10.1'
|
host: '192.168.10.1'
|
||||||
up-script: test
|
up-script: test
|
||||||
register: netwatch_idem
|
register: netwatch_idem
|
||||||
failed_when: ( netwatch_idem | changed )
|
failed_when: (
|
||||||
|
not ansible_check_mode
|
||||||
|
) and (
|
||||||
|
( netwatch_idem | changed )
|
||||||
|
)
|
||||||
|
|
||||||
- name: ALWAYS_CHANGES edit netwatch item, change up-script
|
- name: ALWAYS_CHANGES edit netwatch item, change up-script
|
||||||
mt_tool:
|
mt_tool:
|
||||||
|
@ -1552,7 +1560,11 @@
|
||||||
host: '192.168.10.1'
|
host: '192.168.10.1'
|
||||||
up-script: test2
|
up-script: test2
|
||||||
register: netwatch_edit
|
register: netwatch_edit
|
||||||
failed_when: not ( netwatch_edit | changed )
|
failed_when: (
|
||||||
|
not ansible_check_mode
|
||||||
|
) and (
|
||||||
|
not ( netwatch_edit | changed )
|
||||||
|
)
|
||||||
|
|
||||||
- name: ALWAYS_CHANGES remove netwatch item
|
- name: ALWAYS_CHANGES remove netwatch item
|
||||||
mt_tool:
|
mt_tool:
|
||||||
|
@ -1564,7 +1576,11 @@
|
||||||
settings:
|
settings:
|
||||||
host: '192.168.10.1'
|
host: '192.168.10.1'
|
||||||
register: netwatch_rem
|
register: netwatch_rem
|
||||||
failed_when: not ( netwatch_rem | changed )
|
failed_when: (
|
||||||
|
not ansible_check_mode
|
||||||
|
) and (
|
||||||
|
not ( netwatch_rem | changed )
|
||||||
|
)
|
||||||
|
|
||||||
tags: tool
|
tags: tool
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue