def main(): """Main function""" module = GcpModule(argument_spec=dict( state=dict( default='present', choices=['present', 'absent'], type='str'), name=dict(required=True, type='str'), type=dict(required=True, type='str'), ttl=dict(type='int'), target=dict(type='list', elements='str'), managed_zone=dict(required=True, type='dict'), )) if not module.params['scopes']: module.params['scopes'] = [ 'https://www.googleapis.com/auth/ndev.clouddns.readwrite' ] state = module.params['state'] kind = 'dns#resourceRecordSet' fetch = fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets') changed = False if 'dnsName' not in module.params.get( 'managed_zone') or 'name' not in module.params.get('managed_zone'): module.fail_json( msg= "managed_zone dictionary must contain both the name of the zone and the dns name of the zone" ) if fetch: if state == 'present': if is_different(module, fetch): update(module, self_link(module), kind, fetch) fetch = fetch_resource(module, self_link(module), kind) changed = True else: delete(module, self_link(module), kind, fetch) fetch = {} changed = True else: if state == 'present': fetch = create(module, collection(module), kind) changed = True else: fetch = {} fetch.update({'changed': changed}) module.exit_json(**fetch)
def main(): """Main function""" module = GcpModule(argument_spec=dict( state=dict( default='present', choices=['present', 'absent'], type='str'), name=dict(required=True, type='str'), disable_dependent_services=dict(type='bool'), )) if not module.params['scopes']: module.params['scopes'] = [ 'https://www.googleapis.com/auth/cloud-platform' ] state = module.params['state'] fetch = fetch_resource(module, self_link(module)) changed = False if module.params['state'] == 'present' and module.params[ 'disable_dependent_services']: module.fail_json( msg= "You cannot enable a service and use the disable_dependent_service option" ) if fetch and fetch.get('state') == 'DISABLED': fetch = {} if fetch: if state == 'present': if is_different(module, fetch): update(module, self_link(module)) fetch = fetch_resource(module, self_link(module)) changed = True else: delete(module, delete_link(module)) fetch = {} changed = True else: if state == 'present': fetch = create(module, create_link(module)) changed = True else: fetch = {} fetch.update({'changed': changed}) module.exit_json(**fetch)
def main(): """Main function""" module = GcpModule(argument_spec=dict( state=dict( default='present', choices=['present', 'absent'], type='str'), action=dict(type='str'), overwrite=dict(type='bool'), src=dict(type='path'), dest=dict(type='path'), bucket=dict(type='str'), )) if not module.params['scopes']: module.params['scopes'] = [ 'https://www.googleapis.com/auth/devstorage.full_control' ] remote_object = fetch_resource(module, self_link(module)) local_file_exists = os.path.isfile(local_file_path(module)) # Check if files exist. if module.params['action'] == 'download' and not remote_object: module.fail_json(msg="File does not exist in bucket") if module.params['action'] == 'upload' and not local_file_exists: module.fail_json(msg="File does not exist on disk") # Check if we'll be overwriting files. if not module.params['overwrite']: remote_object['changed'] = False if module.params['action'] == 'download' and local_file_exists: # If files differ, throw an error if get_md5_local( local_file_path(module)) != remote_object['md5Hash']: module.fail_json( msg="Local file is different than remote file") # If files are the same, module is done running. else: module.exit_json(**remote_object) elif module.params['action'] == 'upload' and remote_object: # If files differ, throw an error if get_md5_local( local_file_path(module)) != remote_object['md5Hash']: module.fail_json( msg="Local file is different than remote file") # If files are the same, module is done running. else: module.exit_json(**remote_object) # Upload/download the files auth = GcpSession(module, 'storage') if module.params['action'] == 'download': results = download_file(module) else: results = upload_file(module) module.exit_json(**results)