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( action=dict(type="str", choices=["download", "upload", "delete"]), src=dict(type="path"), dest=dict(type="path"), bucket=dict(type="str"), )) if not HAS_GOOGLE_STORAGE_LIBRARY: module.fail_json( msg="Please install the google-cloud-storage Python library") if not module.params["scopes"]: module.params["scopes"] = [ "https://www.googleapis.com/auth/devstorage.full_control" ] creds = GcpSession(module, "storage")._credentials() client = storage.Client( project=module.params['project'], credentials=creds, client_info=ClientInfo(user_agent="Google-Ansible-MM-object")) bucket = client.get_bucket(module.params['bucket']) remote_file_exists = Blob(remote_file_path(module), bucket).exists() local_file_exists = os.path.isfile(local_file_path(module)) # Check if files exist. results = {} if module.params["action"] == "delete" and not remote_file_exists: module.fail_json(msg="File does not exist in bucket") if module.params["action"] == "download" and not remote_file_exists: 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") if module.params["action"] == "delete": if remote_file_exists: results = delete_file(module, client, module.params["src"]) results["changed"] = True module.params["changed"] = True elif module.params["action"] == "download": results = download_file(module, client, module.params["src"], module.params["dest"]) results["changed"] = True # Upload else: results = upload_file(module, client, module.params["src"], module.params["dest"]) results["changed"] = True module.exit_json(**results)