def main(): module = AnsibleModule( argument_spec = dict( name = dict(required=True, type='str'), state = dict(required=True, type='str', choices=["present", "absent"]), username = dict(required=True, type='str'), password = dict(required=True, type='str'), hostname = dict(required=True, type='str'), plc_name = dict(required=True, type='str'), ) ) credentials = {"username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"]} state = module.params["state"] siteName = module.params["name"] api = LCDNAPI(credentials) sites = api.ListAll("Site", {"name": siteName}) if sites and (state=="absent"): api.deleteSite(siteName) module.exit_json(changed=True, msg="site deleted") elif (not sites) and (state=="present"): api.createSite(siteName) module.exit_json(changed=True, msg="site created") else: module.exit_json(changed=False)
def main(): module = AnsibleModule(argument_spec=dict( cdn_prefix=dict(required=True, type='str'), enabled=dict(required=True, type="bool"), service=dict(default="HyperCache", type="str"), content_provider=dict(required=True, type="str"), default_origin_server=dict(required=True, type="str"), state=dict(required=True, type='str', choices=["present", "absent"]), force=dict(default=False, type="bool"), username=dict(required=True, type='str'), password=dict(required=True, type='str'), hostname=dict(required=True, type='str'), plc_name=dict(required=True, type='str'), )) credentials = { "username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"] } state = module.params["state"] cdn_prefix = module.params["cdn_prefix"] force = module.params["force"] api = LCDNAPI(credentials, experimental=True) content_providers = api.onevapi.ListAll( "ContentProvider", {"name": module.params["content_provider"]}) if not content_providers: raise Exception("Unable to find %s" % module.params["content_provider"]) content_provider = content_providers[0] prefixes = api.onevapi.ListAll("CDNPrefix", {"cdn_prefix": cdn_prefix}) if (prefixes or force) and (state == "absent"): api.Delete("CDNPrefix", prefixes[0]["cdn_prefix_id"]) module.exit_json(changed=True, msg="cdn prefix deleted") elif ((not prefixes) or force) and (state == "present"): if prefixes: # must have been called with force=True, so delete the node so we can re-create it api.onevapi.Delete("CDNPrefix", prefixes[0]["cdn_prefix_id"]) cdn_prefix = { "cdn_prefix": cdn_prefix, "enabled": module.params["enabled"], "service": module.params["service"], "content_provider_id": content_provider["content_provider_id"], "default_origin_server": module.params["default_origin_server"] } ret = api.onevapi.Create("CDNPrefix", cdn_prefix) module.exit_json(changed=True, msg="sp created") else: module.exit_json(changed=False)
def main(): module = AnsibleModule(argument_spec=dict( name=dict(required=True, type='str'), account=dict(required=True, type='str'), enabled=dict(required=True, type="bool"), service_provider=dict(required=True, type="str"), state=dict(required=True, type='str', choices=["present", "absent"]), force=dict(default=False, type="bool"), username=dict(required=True, type='str'), password=dict(required=True, type='str'), hostname=dict(required=True, type='str'), plc_name=dict(required=True, type='str'), )) credentials = { "username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"] } state = module.params["state"] cp_name = module.params["name"] force = module.params["force"] api = LCDNAPI(credentials, experimental=True) service_providers = api.onevapi.ListAll( "ServiceProvider", {"name": module.params["service_provider"]}) if not service_providers: raise Exception("Unable to find %s" % module.params["service_provider"]) service_provider = service_providers[0] cps = api.onevapi.ListAll("ContentProvider", {"name": cp_name}) if (cps or force) and (state == "absent"): api.Delete("ContentProvider", cps[0].id) module.exit_json(changed=True, msg="cp deleted") elif ((not cps) or force) and (state == "present"): if cps: # must have been called with force=True, so delete the node so we can re-create it api.onevapi.Delete("ContentProvider", cps[0]["content_provider_id"]) sp = { "account": module.params["account"], "name": cp_name, "enabled": module.params["enabled"], "service_provider_id": service_provider["service_provider_id"] } ret = api.onevapi.Create("ContentProvider", sp) module.exit_json(changed=True, msg="cp created") else: module.exit_json(changed=False)
def main(): module = AnsibleModule(argument_spec=dict( url=dict(required=True, type='str'), service_type=dict(default="HyperCache", type="str"), content_provider=dict(required=True, type="str"), state=dict(required=True, type='str', choices=["present", "absent"]), force=dict(default=False, type="bool"), username=dict(required=True, type='str'), password=dict(required=True, type='str'), hostname=dict(required=True, type='str'), plc_name=dict(required=True, type='str'), )) credentials = { "username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"] } state = module.params["state"] origin_url = module.params["url"] force = module.params["force"] api = LCDNAPI(credentials, experimental=True) content_providers = api.onevapi.ListAll( "ContentProvider", {"name": module.params["content_provider"]}) if not content_providers: raise Exception("Unable to find %s" % module.params["content_provider"]) content_provider = content_providers[0] origins = api.onevapi.ListAll("OriginServer", {"url": origin_url}) if (origins or force) and (state == "absent"): api.Delete("OriginServer", origins[0]["origin_servier_id"]) module.exit_json(changed=True, msg="origin server deleted") elif ((not origins) or force) and (state == "present"): if origins: # must have been called with force=True, so delete the node so we can re-create it api.onevapi.Delete("OriginServer", origins[0]["origin_server_id"]) origin = { "url": origin_url, "service_type": module.params["service_type"], "content_provider_id": content_provider["content_provider_id"] } ret = api.onevapi.Create("OriginServer", origin) module.exit_json(changed=True, msg="origin server created") else: module.exit_json(changed=False)
def main(): module = AnsibleModule(argument_spec=dict( name=dict(required=True, type='str'), site=dict(required=True, type='str'), dns=dict(required=True, type='list'), interfaces=dict(required=True, type='list'), license=dict(required=True, type='str'), state=dict(required=True, type='str', choices=["present", "absent"]), force=dict(default=False, type="bool"), username=dict(required=True, type='str'), password=dict(required=True, type='str'), hostname=dict(required=True, type='str'), plc_name=dict(required=True, type='str'), remote_hostname=dict(default=None, type="str"), )) credentials = { "username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"] } state = module.params["state"] node_hostname = module.params["name"] eorce = module.params["force"] api = LCDNAPI(credentials) nodes = api.ListAll("Node", {"hostname": node_hostname}) if (nodes or force) and (state == "absent"): api.deleteCache(node_hostname) module.exit_json(changed=True, msg="cachenode deleted") elif ((not nodes) or force) and (state == "present"): if nodes: # must have been called with force=True, so delete the node so we can re-create it api.deleteCache(node_hostname) hpc = { "hostname": node_hostname, "site": module.params["site"], "dns": module.params["dns"], "Interfaces": module.params["interfaces"], "license": module.params["license"] } ret = api.createCache(**hpc) setupscript = ret["setupscript"] if module.params["remote_hostname"]: setupscript = setupscript.replace(module.params["hostname"], module.params["remote_hostname"]) module.exit_json(changed=True, msg="cachenode created", setupscript=setupscript) else: module.exit_json(changed=False)
def main(): module = AnsibleModule(argument_spec=dict( name=dict(required=True, type='str'), state=dict(required=True, type='str', choices=["present", "absent"]), username=dict(required=True, type='str'), password=dict(required=True, type='str'), hostname=dict(required=True, type='str'), plc_name=dict(required=True, type='str'), )) credentials = { "username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"] } state = module.params["state"] siteName = module.params["name"] api = LCDNAPI(credentials) sites = api.ListAll("Site", {"name": siteName}) if sites and (state == "absent"): api.deleteSite(siteName) module.exit_json(changed=True, msg="site deleted") elif (not sites) and (state == "present"): api.createSite(siteName) module.exit_json(changed=True, msg="site created") else: module.exit_json(changed=False)
def main(): module = AnsibleModule( argument_spec = dict( name = dict(required=True, type='str'), site = dict(required=True, type='str'), dns = dict(required=True, type='list'), interfaces= dict(required=True, type='list'), license = dict(required=True, type='str'), state = dict(required=True, type='str', choices=["present", "absent"]), force = dict(default=False, type="bool"), username = dict(required=True, type='str'), password = dict(required=True, type='str'), hostname = dict(required=True, type='str'), plc_name = dict(required=True, type='str'), remote_hostname = dict(default=None, type="str"), ) ) credentials = {"username": module.params["username"], "password": module.params["password"], "hostname": module.params["hostname"], "plc_name": module.params["plc_name"]} state = module.params["state"] node_hostname = module.params["name"] force = module.params["force"] api = LCDNAPI(credentials) nodes = api.ListAll("Node", {"hostname": node_hostname}) if (nodes or force) and (state=="absent"): api.deleteCache(node_hostname) module.exit_json(changed=True, msg="cachenode deleted") elif ((not nodes) or force) and (state=="present"): if nodes: # must have been called with force=True, so delete the node so we can re-create it api.deleteCache(node_hostname) hpc = {"hostname": node_hostname, "site": module.params["site"], "dns": module.params["dns"], "Interfaces": module.params["interfaces"], "license": module.params["license"]} ret = api.createCache(**hpc) setupscript=ret["setupscript"] if module.params["remote_hostname"]: setupscript = setupscript.replace(module.params["hostname"], module.params["remote_hostname"]) module.exit_json(changed=True, msg="cachenode created", setupscript=setupscript) else: module.exit_json(changed=False)