def main(): with PulpEntityAnsibleModule( argument_spec=dict( repository=dict(), version=dict(type="int"), ), required_if=( ["state", "present", ["repository"]], ["state", "absent", ["repository"]], ), ) as module: repository_name = module.params["repository"] version = module.params["version"] desired_attributes = {} if repository_name: repository = PulpPythonRepository(module, {"name": repository_name}) repository.find(failsafe=False) # TODO check if version exists if version: repository_version_href = repository.entity[ "versions_href"] + "{version}/".format(version=version) else: repository_version_href = repository.entity[ "latest_version_href"] natural_key = {"repository_version": repository_version_href} else: natural_key = {"repository_version": None} PulpPythonPublication(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), namespace=dict(), version=dict(), sha256=dict(aliases=["digest"]), ), required_if=[ ("state", "present", ["name", "namespace", "version", "sha256"]), ("state", "absent", ["name", "namespace", "version"]), ], ) as module: natural_key = { "name": module.params["name"], "namespace": module.params["namespace"], "version": module.params["version"], } desired_attributes = {} if module.params["sha256"]: artifact = PulpArtifact(module, {"sha256": module.params["sha256"]}) artifact.find() desired_attributes["artifact"] = artifact.href PulpAnsibleRole(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), url=dict(), download_concurrency=dict(type="int"), policy=dict(choices=["immediate"],), proxy_url=dict(type="str"), tls_validation=dict(type="bool"), ), required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])], ) as module: natural_key = {"name": module.params["name"]} desired_attributes = { key: module.params[key] for key in [ "url", "download_concurrency", "policy", "proxy_url", "tls_validation", ] if module.params[key] is not None } PulpAnsibleRemote(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), base_path=dict(), publication=dict(), content_guard=dict(), ), required_if=[ ("state", "present", ["name", "base_path"]), ("state", "absent", ["name"]), ], ) as module: content_guard_name = module.params["content_guard"] natural_key = { "name": module.params["name"], } desired_attributes = { key: module.params[key] for key in ["base_path", "publication"] if module.params[key] is not None } if content_guard_name is not None: if content_guard_name: content_guard = PulpContentGuard(module, {"name": content_guard_name}) content_guard.find(failsafe=False) desired_attributes["content_guard"] = content_guard.href else: desired_attributes["content_guard"] = None PulpDebDistribution(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), base_path=dict(), repository=dict(), version=dict(type="int"), content_guard=dict(), ), required_if=[ ("state", "present", ["name", "base_path"]), ("state", "absent", ["name"]), ], ) as module: repository_name = module.params["repository"] version = module.params["version"] content_guard_name = module.params["content_guard"] natural_key = { "name": module.params["name"], } desired_attributes = { key: module.params[key] for key in ["base_path"] if module.params[key] is not None } if repository_name: repository = PulpAnsibleRepository(module, {"name": repository_name}) repository.find() if repository.entity is None: raise SqueezerException( msg="Failed to find repository ({repository_name}).".format( repository_name=repository_name ) ) # TODO check if version exists if version: desired_attributes["repository_version"] = repository.entity[ "versions_href" ] + "{version}/".format(version=version) else: desired_attributes["repository"] = repository.href if content_guard_name is not None: if content_guard_name: content_guard = PulpContentGuard(module, {"name": content_guard_name}) content_guard.find() if content_guard.entity is None: raise SqueezerException( "Content guard {0} not found.".format(content_guard_name) ) desired_attributes["content_guard"] = content_guard.href else: desired_attributes["content_guard"] = None PulpAnsibleDistribution(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict(name=dict(), description=dict()), required_if=[("state", "present", ["name"]), ("state", "absent", ["name"])], ) as module: natural_key = {"name": module.params["name"]} desired_attributes = {} if module.params["description"] is not None: # In case of an empty string we nullify the description desired_attributes["description"] = module.params["description"] or None PulpRpmRepository(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( viewset_name=dict(), statements=dict( type="list", elements="dict", options=dict( action=dict(required=True, type="list", elements="str"), principal=dict(required=True), condition=dict(type="raw"), effect=dict(required=True, choices=["allow", "deny"]), ), ), creation_hooks=dict( type="list", elements="dict", options=dict( function=dict(required=True), parameters=dict(required=True, type="raw"), permissions=dict(type="list", elements="str"), ), aliases=["permissions_assignment"], ), state=dict(choices=["present"]), ), required_if=[("state", "present", ["viewset_name"])], ) as module: natural_key = {"viewset_name": module.params["viewset_name"]} desired_attributes = { key: module.params[key] for key in ["statements", "creation_hooks"] if module.params[key] is not None } if "statements" in desired_attributes: for statement in desired_attributes["statements"]: if statement["condition"] is None: del statement["condition"] # Workaround for rename "permissions_assignment" -> "creation_hooks" core_version = (module.pulp_api.api_spec.get("info", {}).get( "x-pulp-app-versions", {}).get("core", ())) if pulp_parse_version(core_version) < pulp_parse_version("3.17.0"): if "creation_hooks" in desired_attributes: desired_attributes[ "permissions_assignment"] = desired_attributes.pop( "creation_hooks") PulpAccessPolicy(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), base_path=dict(), repository=dict(), version=dict(type="int"), content_guard=dict(), private=dict(type="bool"), ), required_if=[ ("state", "present", ["name", "base_path"]), ("state", "absent", ["name"]), ], ) as module: repository_name = module.params["repository"] version = module.params["version"] content_guard_name = module.params["content_guard"] private = module.params["private"] natural_key = {"name": module.params["name"]} desired_attributes = { key: module.params[key] for key in ["base_path", "private"] if module.params[key] is not None } if repository_name: repository = PulpContainerRepository(module, {"name": repository_name}) repository.find(failsafe=False) # TODO check if version exists if version: desired_attributes["repository_version"] = repository.entity[ "versions_href"] + "{version}/".format(version=version) else: desired_attributes["repository"] = repository.href if content_guard_name is not None: if content_guard_name: content_guard = PulpContentGuard(module, {"name": content_guard_name}) content_guard.find(failsafe=False) desired_attributes["content_guard"] = content_guard.href else: desired_attributes["content_guard"] = None PulpContainerDistribution(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( repository=dict(), version=dict(type="int"), mode=dict( default="simple", choices=["structured", "simple", "simple_and_structured", "verbatim"], ), ), required_if=( ["state", "present", ["repository"]], ["state", "absent", ["repository"]], ), ) as module: repository_name = module.params["repository"] version = module.params["version"] mode = module.params["mode"] if mode == "verbatim": desired_attributes = {} else: desired_attributes = { "simple": "simple" in mode, "structured": "structured" in mode, } if repository_name: repository = PulpDebRepository(module, {"name": repository_name}) repository.find(failsafe=False) # TODO check if version exists if version: repository_version_href = repository.entity[ "versions_href" ] + "{version}/".format(version=version) else: repository_version_href = repository.entity["latest_version_href"] natural_key = {"repository_version": repository_version_href} else: natural_key = {"repository_version": None} if mode == "verbatim": PulpDebVerbatimPublication( module, natural_key, desired_attributes ).process() else: PulpDebPublication(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( pulp_href=dict(), state=dict(choices=["absent", "canceled", "completed"], ), ), required_if=[ ("state", "absent", ["pulp_href"]), ("state", "canceled", ["pulp_href"]), ("state", "completed", ["pulp_href"]), ], ) as module: natural_key = {"pulp_href": module.params["pulp_href"]} desired_attributes = {} PulpTask(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( sha256=dict(aliases=["digest"]), relative_path=dict(), ), required_if=[ ("state", "present", ["sha256", "relative_path"]), ("state", "absent", ["sha256", "relative_path"]), ], ) as module: natural_key = { "sha256": module.params["sha256"], "relative_path": module.params["relative_path"], } desired_attributes = {} PulpFileContent(module, natural_key, desired_attributes).process()
def main(): with PulpEntityAnsibleModule( argument_spec=dict( name=dict(), base_path=dict(), publication=dict(), content_guard=dict(), ), required_if=[ ("state", "present", ["name", "base_path"]), ("state", "absent", ["name"]), ], ) as module: content_guard_name = module.params["content_guard"] natural_key = { "name": module.params["name"], } desired_attributes = { key: module.params[key] for key in ["base_path", "publication"] if module.params[key] is not None } if content_guard_name is not None: if content_guard_name: content_guard = PulpContentGuard(module, {"name": content_guard_name}) content_guard.find() if content_guard.entity is None: raise SqueezerException( "Content guard {0} not found.".format( content_guard_name)) desired_attributes["content_guard"] = content_guard.href else: desired_attributes["content_guard"] = None PulpFileDistribution(module, natural_key, desired_attributes).process()