diff --git a/plugins/module_utils/ah_api_module.py b/plugins/module_utils/ah_api_module.py index 409c7e98..96cd527a 100644 --- a/plugins/module_utils/ah_api_module.py +++ b/plugins/module_utils/ah_api_module.py @@ -16,6 +16,8 @@ import json import time +from ansible.module_utils.compat.version import LooseVersion as Version + from ansible.module_utils.basic import AnsibleModule, env_fallback from ansible.module_utils._text import to_bytes, to_text @@ -134,7 +136,7 @@ def __init__(self, argument_spec, direct_params=None, **kwargs): self.plugin_path_prefix = "{galaxy_prefix}/v3/plugin".format(galaxy_prefix=self.galaxy_path_prefix) self.authenticate() self.server_version = self.get_server_version() - if self.server_version < "4.6": + if Version(self.server_version) < Version("4.6"): self.pulp_path_prefix = "/pulp/api/v3" else: self.pulp_path_prefix = "{galaxy_prefix}/pulp/api/v3".format(galaxy_prefix=self.galaxy_path_prefix) @@ -485,7 +487,7 @@ def exit_json(self, **kwargs): def get_server_version(self): """Return the automation hub/galaxy server version. - :return: the server version ("4.2.5" for example) or an empty string if + :return: the server version ("4.2.5" for example) or an "0" string if that information is not available. :rtype: str """ @@ -501,4 +503,4 @@ def get_server_version(self): else: fail_msg = "Unable to get server version: {code}".format(code=response["status_code"]) self.fail_json(msg=fail_msg) - return response["json"]["server_version"].replace('dev', '') if "server_version" in response["json"] else "" + return response["json"]["server_version"].replace('dev', '') if "server_version" in response["json"] else "0" diff --git a/plugins/module_utils/ah_ui_object.py b/plugins/module_utils/ah_ui_object.py index 6240e1fa..989d0216 100644 --- a/plugins/module_utils/ah_ui_object.py +++ b/plugins/module_utils/ah_ui_object.py @@ -9,6 +9,8 @@ from __future__ import absolute_import, division, print_function import time + +from ansible.module_utils.compat.version import LooseVersion as Version from .ah_api_module import AHAPIModuleError from .ah_pulp_object import AHPulpTask @@ -1070,7 +1072,7 @@ def get_object(self, name, vers, exit_on_error=True): """ query = {self.name_field: name, "limit": "1000"} self.vers = vers - if vers < "4.7": + if Version(vers) < Version("4.7"): url = self.api.build_ui_url(self.endpoint, query_params=query) else: url = self.api.build_plugin_url(self.endpoint, query_params=query) @@ -1158,7 +1160,7 @@ def sync(self, wait, interval, timeout): :rtype: bool """ - if self.vers < "4.7": + if Version(self.vers) < Version("4.7"): url = self.api.build_ui_url("{endpoint}/_content/sync".format(endpoint=self.id_endpoint)) else: url = self.api.build_plugin_url("{endpoint}/_content/sync".format(endpoint=self.id_endpoint)) @@ -1230,7 +1232,7 @@ def get_readme(self): if not self.exists: return "" - if self.vers < "4.7": + if Version(self.vers) < Version("4.7"): url = self.api.build_ui_url("{endpoint}/_content/readme".format(endpoint=self.id_endpoint)) else: url = self.api.build_plugin_url("{endpoint}/_content/readme".format(endpoint=self.id_endpoint)) @@ -1289,7 +1291,7 @@ def update_readme(self, readme, auto_exit=True): self.api.exit_json(**json_output) return True - if self.vers < "4.7": + if Version(self.vers) < Version("4.7"): url = self.api.build_ui_url("{endpoint}/_content/readme".format(endpoint=self.id_endpoint)) else: url = self.api.build_plugin_url("{endpoint}/_content/readme".format(endpoint=self.id_endpoint)) @@ -1579,7 +1581,7 @@ def get_tag(self, name, tag, vers): self.image_name = name self.tag = tag self.vers = vers - if vers < "4.7": + if Version(vers) < Version("4.7"): url = self.api.build_ui_url(self.id_endpoint, query_params={"limit": 1000}) else: url = self.api.build_plugin_url(self.id_endpoint, query_params={"limit": 1000}) diff --git a/plugins/modules/ah_ee_image.py b/plugins/modules/ah_ee_image.py index de72e987..7eafd9ba 100644 --- a/plugins/modules/ah_ee_image.py +++ b/plugins/modules/ah_ee_image.py @@ -90,6 +90,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIEEImage from ..module_utils.ah_pulp_object import AHPulpEERepository @@ -121,7 +122,7 @@ def main(): # Only recent versions support execution environment vers = module.get_server_version() - if vers < "4.3.2": + if Version(vers) < Version("4.3.2"): module.fail_json(msg="This module requires private automation hub version 4.3.2 or later. Your version is {vers}".format(vers=vers)) # Process the object from the Pulp API (delete or create) diff --git a/plugins/modules/ah_ee_namespace.py b/plugins/modules/ah_ee_namespace.py index 167a0da4..455626e7 100644 --- a/plugins/modules/ah_ee_namespace.py +++ b/plugins/modules/ah_ee_namespace.py @@ -125,6 +125,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule, AHAPIModuleError from ..module_utils.ah_ui_object import AHUIGroup, AHUIEENamespace from ..module_utils.ah_pulp_object import AHPulpEENamespace, AHPulpEERepository @@ -234,9 +235,9 @@ def main(): # Only recent versions support execution environment vers = module.get_server_version() - if vers > "4.6.3": + if Version(vers) > Version("4.6.3"): module.fail_json(msg="This module requires private automation hub version 4.6.2 or earlier. Your version is {vers}".format(vers=vers)) - elif vers < "4.3.2": + elif Version(vers) < Version("4.3.2"): module.fail_json(msg="This module requires private automation hub version 4.3.2 or later. Your version is {vers}".format(vers=vers)) # Process the object from the Pulp API (delete or create) diff --git a/plugins/modules/ah_ee_registry.py b/plugins/modules/ah_ee_registry.py index 1b5495b1..ab02afeb 100644 --- a/plugins/modules/ah_ee_registry.py +++ b/plugins/modules/ah_ee_registry.py @@ -142,6 +142,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIEERegistry @@ -189,7 +190,7 @@ def main(): module.authenticate() vers = module.get_server_version() registry = AHUIEERegistry(module) - if vers > "4.7.0": + if Version(vers) > Version("4.7.0"): registry.id_field = "id" # Removing the registry if state == "absent": diff --git a/plugins/modules/ah_ee_registry_index.py b/plugins/modules/ah_ee_registry_index.py index 0c93477a..59010708 100644 --- a/plugins/modules/ah_ee_registry_index.py +++ b/plugins/modules/ah_ee_registry_index.py @@ -66,6 +66,7 @@ timeout: 300 """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIEERegistry @@ -91,7 +92,7 @@ def main(): module.authenticate() vers = module.get_server_version() registry = AHUIEERegistry(module) - if vers > "4.7.0": + if Version(vers) > Version("4.7.0"): registry.id_field = "id" registry.get_object(name, vers) diff --git a/plugins/modules/ah_ee_registry_sync.py b/plugins/modules/ah_ee_registry_sync.py index fe23f739..b5424695 100644 --- a/plugins/modules/ah_ee_registry_sync.py +++ b/plugins/modules/ah_ee_registry_sync.py @@ -64,6 +64,7 @@ timeout: 300 """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIEERegistry @@ -90,7 +91,7 @@ def main(): vers = module.get_server_version() registry = AHUIEERegistry(module) registry.get_object(name, vers) - if vers > "4.7.0": + if Version(vers) > Version("4.7.0"): registry.id_field = "id" if not registry.exists: diff --git a/plugins/modules/ah_ee_repository.py b/plugins/modules/ah_ee_repository.py index 4b58ec3b..9faade95 100644 --- a/plugins/modules/ah_ee_repository.py +++ b/plugins/modules/ah_ee_repository.py @@ -129,6 +129,7 @@ import os import os.path +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIEERepository, AHUIEERegistry, AHUIEERemote from ..module_utils.ah_pulp_object import AHPulpEERepository, AHPulpEENamespace @@ -187,9 +188,9 @@ def main(): # Only recent versions support execution environment vers = module.get_server_version() - if vers < "4.3.2": + if Version(vers) < Version("4.3.2"): module.fail_json(msg="This module requires private automation hub version 4.3.2 or later. Your version is {vers}".format(vers=vers)) - elif vers < "4.4.0" and registry: + elif Version(vers) < Version("4.4.0") and registry: module.fail_json( msg="This module requires private automation hub version 4.4.0 or later to create remote repositories. Your version is {vers}".format(vers=vers) ) diff --git a/plugins/modules/ah_group.py b/plugins/modules/ah_group.py index 97e18965..a6d8071b 100644 --- a/plugins/modules/ah_group.py +++ b/plugins/modules/ah_group.py @@ -63,6 +63,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIGroup from ..module_utils.ah_pulp_object import AHPulpGroups @@ -82,10 +83,10 @@ def main(): state = module.params.get("state") # Authenticate module.authenticate() - vers = module.get_server_version() + vers = Version(module.get_server_version()) # Use Pulp with newer versions - if vers > "4.7.0": + if vers > Version("4.7.0"): group = AHPulpGroups(module) group.get_object(name) else: diff --git a/plugins/modules/ah_group_perm.py b/plugins/modules/ah_group_perm.py index 59adaf2d..b90dc423 100644 --- a/plugins/modules/ah_group_perm.py +++ b/plugins/modules/ah_group_perm.py @@ -119,6 +119,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_ui_object import AHUIGroup @@ -188,7 +189,7 @@ def main(): module.authenticate() vers = module.get_server_version() - if vers < "4.3.2": + if Version(vers) < Version("4.3.2"): del FRIENDLY_PERM_NAMES["change_containernamespace_perms"] del FRIENDLY_PERM_NAMES["change_container"] del FRIENDLY_PERM_NAMES["change_image_tag"] diff --git a/plugins/modules/ah_role.py b/plugins/modules/ah_role.py index ecb2be7f..b5b11321 100644 --- a/plugins/modules/ah_role.py +++ b/plugins/modules/ah_role.py @@ -113,6 +113,7 @@ RETURN = r""" # """ +from ansible.module_utils.compat.version import LooseVersion as Version from ..module_utils.ah_api_module import AHAPIModule from ..module_utils.ah_pulp_object import AHPulpRolePerm @@ -194,7 +195,7 @@ def main(): # Only recent versions support execution environment vers = module.get_server_version() - if vers < "4.6": + if Version(vers) < Version("4.6"): module.fail_json(msg="This module requires private automation hub version 4.6 or later. Your version is {vers}".format(vers=vers)) # Process the object from the Pulp API (delete or create)