def main(): fields = dict(operation=dict(type='str', required=True), path_params=dict(type='dict'), destination=dict(type='path', required=True)) module = AnsibleModule(argument_spec=fields, supports_check_mode=True) params = module.params connection = Connection(module._socket_path) op_name = params['operation'] op_spec = connection.get_operation_spec(op_name) if op_spec is None: module.fail_json(msg='Operation with specified name is not found: %s' % op_name) if not is_download_operation(op_spec): module.fail_json( msg= 'Invalid download operation: %s. The operation must make GET request and return a file.' % op_name) try: path_params = params['path_params'] validate_params(connection, op_name, path_params) if module.check_mode: module.exit_json(changed=False) connection.download_file(op_spec[OperationField.URL], params['destination'], path_params) module.exit_json(changed=False) except FtdServerError as e: module.fail_json( msg='Download request for %s operation failed. Status code: %s. ' 'Server response: %s' % (op_name, e.code, e.response)) except ValidationError as e: module.fail_json(msg=e.args[0])
def main(): fields = dict( operation=dict(type='str', required=True), file_to_upload=dict(type='path', required=True), register_as=dict(type='str'), ) module = AnsibleModule(argument_spec=fields, supports_check_mode=True) params = module.params connection = Connection(module._socket_path) op_spec = connection.get_operation_spec(params['operation']) if op_spec is None: module.fail_json(msg='Operation with specified name is not found: %s' % params['operation']) if not is_upload_operation(op_spec): module.fail_json( msg= 'Invalid upload operation: %s. The operation must make POST request and return UploadStatus model.' % params['operation']) try: if module.check_mode: module.exit_json() resp = connection.upload_file(params['file_to_upload'], op_spec[OperationField.URL]) module.exit_json(changed=True, response=resp, ansible_facts=construct_ansible_facts( resp, module.params)) except FtdServerError as e: module.fail_json( msg='Upload request for %s operation failed. Status code: %s. ' 'Server response: %s' % (params['operation'], e.code, e.response))