PR to support Ansible Checkmode in Checkpoint modules (#57695)
* added checkmode support Signed-off-by: Sumit Jaiswal <sjaiswal@redhat.com>
This commit is contained in:
parent
b01b1d40cf
commit
b2d8ef69f9
2 changed files with 31 additions and 28 deletions
|
@ -169,9 +169,22 @@ def api_call(module, api_call_object):
|
|||
result = {'changed': False}
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
if equals_code == 200:
|
||||
if not equals_response['equals']:
|
||||
code, response = send_request(connection, version, 'set-' + api_call_object, payload)
|
||||
if not module.check_mode:
|
||||
if equals_code == 200:
|
||||
if not equals_response['equals']:
|
||||
code, response = send_request(connection, version, 'set-' + api_call_object, payload)
|
||||
if code != 200:
|
||||
module.fail_json(msg=response)
|
||||
|
||||
handle_publish(module, connection, version)
|
||||
|
||||
result['changed'] = True
|
||||
result[api_call_object] = response
|
||||
else:
|
||||
# objects are equals and there is no need for set request
|
||||
pass
|
||||
elif equals_code == 404:
|
||||
code, response = send_request(connection, version, 'add-' + api_call_object, payload)
|
||||
if code != 200:
|
||||
module.fail_json(msg=response)
|
||||
|
||||
|
@ -179,31 +192,19 @@ def api_call(module, api_call_object):
|
|||
|
||||
result['changed'] = True
|
||||
result[api_call_object] = response
|
||||
else:
|
||||
# objects are equals and there is no need for set request
|
||||
elif module.params['state'] == 'absent':
|
||||
if not module.check_mode:
|
||||
if equals_code == 200:
|
||||
code, response = send_request(connection, version, 'delete-' + api_call_object, payload)
|
||||
if code != 200:
|
||||
module.fail_json(msg=response)
|
||||
|
||||
handle_publish(module, connection, version)
|
||||
|
||||
result['changed'] = True
|
||||
elif equals_code == 404:
|
||||
# no need to delete because object dose not exist
|
||||
pass
|
||||
elif equals_code == 404:
|
||||
code, response = send_request(connection, version, 'add-' + api_call_object, payload)
|
||||
if code != 200:
|
||||
module.fail_json(msg=response)
|
||||
|
||||
handle_publish(module, connection, version)
|
||||
|
||||
result['changed'] = True
|
||||
result[api_call_object] = response
|
||||
else:
|
||||
# state == absent
|
||||
if equals_code == 200:
|
||||
code, response = send_request(connection, version, 'delete-' + api_call_object, payload)
|
||||
if code != 200:
|
||||
module.fail_json(msg=response)
|
||||
|
||||
handle_publish(module, connection, version)
|
||||
|
||||
result['changed'] = True
|
||||
elif equals_code == 404:
|
||||
# no need to delete because object dose not exist
|
||||
pass
|
||||
|
||||
result['checkpoint_session_uid'] = connection.get_session_uid()
|
||||
return result
|
||||
|
|
|
@ -196,7 +196,9 @@ def main():
|
|||
argument_spec.update(checkpoint_argument_spec_for_objects)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec, required_one_of=[['name', 'uid']],
|
||||
mutually_exclusive=[['name', 'uid']])
|
||||
mutually_exclusive=[['name', 'uid']],
|
||||
supports_check_mode=True)
|
||||
|
||||
api_call_object = 'network'
|
||||
|
||||
result = api_call(module, api_call_object)
|
||||
|
|
Loading…
Reference in a new issue