diff --git a/changelogs/fragments/3936-distutils.version.yml b/changelogs/fragments/3936-distutils.version.yml new file mode 100644 index 0000000000..bf6ea7f715 --- /dev/null +++ b/changelogs/fragments/3936-distutils.version.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Various modules and plugins - use vendored version of ``distutils.version`` included in ansible-core 2.12 if available. This avoids breakage when ``distutils`` is removed from the standard library of Python 3.12. Note that ansible-core 2.11, ansible-base 2.10 and Ansible 2.9 are right now not compatible with Python 3.12, hence this fix does not target these ansible-core/-base/2.9 versions (https://github.com/ansible-collections/community.general/pull/3936)." diff --git a/plugins/filter/version_sort.py b/plugins/filter/version_sort.py index c59e87c9c6..ac62ef8c8f 100644 --- a/plugins/filter/version_sort.py +++ b/plugins/filter/version_sort.py @@ -5,7 +5,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from distutils.version import LooseVersion +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion def version_sort(value, reverse=False): diff --git a/plugins/inventory/cobbler.py b/plugins/inventory/cobbler.py index d9bc549ed6..7292171f1a 100644 --- a/plugins/inventory/cobbler.py +++ b/plugins/inventory/cobbler.py @@ -68,7 +68,6 @@ user: ansible-tester password: secure ''' -from distutils.version import LooseVersion import socket from ansible.errors import AnsibleError diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index f52f0f1bb3..9d324975b3 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -119,12 +119,13 @@ compose: import re from ansible.module_utils.common._collections_compat import MutableMapping -from distutils.version import LooseVersion from ansible.errors import AnsibleError from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable from ansible.module_utils.six.moves.urllib.parse import urlencode +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + # 3rd party imports try: import requests diff --git a/plugins/inventory/xen_orchestra.py b/plugins/inventory/xen_orchestra.py index 1e19051fe8..8a7d9e7354 100644 --- a/plugins/inventory/xen_orchestra.py +++ b/plugins/inventory/xen_orchestra.py @@ -79,11 +79,11 @@ simple_config_file: import json import ssl -from distutils.version import LooseVersion - from ansible.errors import AnsibleError from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + # 3rd party imports try: HAS_WEBSOCKET = True diff --git a/plugins/module_utils/gitlab.py b/plugins/module_utils/gitlab.py index 1a0bf12a1e..21af10b5cd 100644 --- a/plugins/module_utils/gitlab.py +++ b/plugins/module_utils/gitlab.py @@ -7,11 +7,11 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from distutils.version import StrictVersion - from ansible.module_utils.basic import missing_required_lib from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + try: from urllib import quote_plus # Python 2.X from urlparse import urljoin @@ -79,7 +79,7 @@ def gitlab_authentication(module): # python-gitlab library remove support for username/password authentication since 1.13.0 # Changelog : https://github.com/python-gitlab/python-gitlab/releases/tag/v1.13.0 # This condition allow to still support older version of the python-gitlab library - if StrictVersion(gitlab.__version__) < StrictVersion("1.13.0"): + if LooseVersion(gitlab.__version__) < LooseVersion("1.13.0"): gitlab_instance = gitlab.Gitlab(url=gitlab_url, ssl_verify=validate_certs, email=gitlab_user, password=gitlab_password, private_token=gitlab_token, api_version=4) else: diff --git a/plugins/module_utils/influxdb.py b/plugins/module_utils/influxdb.py index 92c7802335..c171131a95 100644 --- a/plugins/module_utils/influxdb.py +++ b/plugins/module_utils/influxdb.py @@ -9,7 +9,8 @@ __metaclass__ = type import traceback from ansible.module_utils.basic import missing_required_lib -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py new file mode 100644 index 0000000000..d1769e175e --- /dev/null +++ b/plugins/module_utils/version.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright: (c) 2021, Felix Fontein +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +"""Provide version object to compare version numbers.""" + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from ansible.module_utils.six import raise_from + +try: + from ansible.module_utils.compat.version import LooseVersion +except ImportError: + try: + from distutils.version import LooseVersion + except ImportError as exc: + msg = 'To use this plugin or module with ansible-core < 2.11, you need to use Python < 3.12 with distutils.version present' + raise_from(ImportError(msg), exc) diff --git a/plugins/modules/cloud/centurylink/clc_aa_policy.py b/plugins/modules/cloud/centurylink/clc_aa_policy.py index 1d52cca7c5..416a4a6c1f 100644 --- a/plugins/modules/cloud/centurylink/clc_aa_policy.py +++ b/plugins/modules/cloud/centurylink/clc_aa_policy.py @@ -120,7 +120,7 @@ __version__ = '${version}' import os import traceback -from distutils.version import LooseVersion +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/modules/cloud/centurylink/clc_alert_policy.py b/plugins/modules/cloud/centurylink/clc_alert_policy.py index de9d146dc4..b6ed6e96ef 100644 --- a/plugins/modules/cloud/centurylink/clc_alert_policy.py +++ b/plugins/modules/cloud/centurylink/clc_alert_policy.py @@ -161,7 +161,8 @@ __version__ = '${version}' import json import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/modules/cloud/centurylink/clc_blueprint_package.py b/plugins/modules/cloud/centurylink/clc_blueprint_package.py index bd0e868fa3..4e03062ba7 100644 --- a/plugins/modules/cloud/centurylink/clc_blueprint_package.py +++ b/plugins/modules/cloud/centurylink/clc_blueprint_package.py @@ -89,7 +89,8 @@ __version__ = '${version}' import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -132,8 +133,7 @@ class ClcBlueprintPackage: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/centurylink/clc_firewall_policy.py b/plugins/modules/cloud/centurylink/clc_firewall_policy.py index a8f8a4e5f0..3fc0427692 100644 --- a/plugins/modules/cloud/centurylink/clc_firewall_policy.py +++ b/plugins/modules/cloud/centurylink/clc_firewall_policy.py @@ -162,7 +162,8 @@ import os import traceback from ansible.module_utils.six.moves.urllib.parse import urlparse from time import sleep -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -203,8 +204,7 @@ class ClcFirewallPolicy: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/centurylink/clc_group.py b/plugins/modules/cloud/centurylink/clc_group.py index e1c05c6c0c..312c626914 100644 --- a/plugins/modules/cloud/centurylink/clc_group.py +++ b/plugins/modules/cloud/centurylink/clc_group.py @@ -207,7 +207,8 @@ __version__ = '${version}' import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/modules/cloud/centurylink/clc_loadbalancer.py b/plugins/modules/cloud/centurylink/clc_loadbalancer.py index 950e087976..bf09ce22be 100644 --- a/plugins/modules/cloud/centurylink/clc_loadbalancer.py +++ b/plugins/modules/cloud/centurylink/clc_loadbalancer.py @@ -210,7 +210,8 @@ import json import os import traceback from time import sleep -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -255,8 +256,7 @@ class ClcLoadBalancer: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/centurylink/clc_modify_server.py b/plugins/modules/cloud/centurylink/clc_modify_server.py index 90a368867e..27cdf614ec 100644 --- a/plugins/modules/cloud/centurylink/clc_modify_server.py +++ b/plugins/modules/cloud/centurylink/clc_modify_server.py @@ -311,7 +311,8 @@ __version__ = '${version}' import json import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -355,8 +356,7 @@ class ClcModifyServer: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/centurylink/clc_publicip.py b/plugins/modules/cloud/centurylink/clc_publicip.py index 1cdb4aa8db..3b4fcc4eed 100644 --- a/plugins/modules/cloud/centurylink/clc_publicip.py +++ b/plugins/modules/cloud/centurylink/clc_publicip.py @@ -117,7 +117,8 @@ __version__ = '${version}' import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/modules/cloud/centurylink/clc_server.py b/plugins/modules/cloud/centurylink/clc_server.py index 95481f1a52..734039875d 100644 --- a/plugins/modules/cloud/centurylink/clc_server.py +++ b/plugins/modules/cloud/centurylink/clc_server.py @@ -433,7 +433,8 @@ import json import os import time import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -478,8 +479,7 @@ class ClcServer: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/centurylink/clc_server_snapshot.py b/plugins/modules/cloud/centurylink/clc_server_snapshot.py index 1f92def088..dbee34bbb2 100644 --- a/plugins/modules/cloud/centurylink/clc_server_snapshot.py +++ b/plugins/modules/cloud/centurylink/clc_server_snapshot.py @@ -101,7 +101,8 @@ __version__ = '${version}' import os import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -145,8 +146,7 @@ class ClcSnapshot: self.module.fail_json(msg=missing_required_lib('clc-sdk'), exception=CLC_IMP_ERR) if not REQUESTS_FOUND: self.module.fail_json(msg=missing_required_lib('requests'), exception=REQUESTS_IMP_ERR) - if requests.__version__ and LooseVersion( - requests.__version__) < LooseVersion('2.5.0'): + if requests.__version__ and LooseVersion(requests.__version__) < LooseVersion('2.5.0'): self.module.fail_json( msg='requests library version should be >= 2.5.0') diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py index 0fb7f1ccae..22e9ad6b7c 100644 --- a/plugins/modules/cloud/misc/proxmox.py +++ b/plugins/modules/cloud/misc/proxmox.py @@ -348,7 +348,8 @@ EXAMPLES = r''' import time import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion try: from proxmoxer import ProxmoxAPI diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 110a78434f..d532433223 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -725,9 +725,10 @@ msg: import re import time import traceback -from distutils.version import LooseVersion from ansible.module_utils.six.moves.urllib.parse import quote +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + try: from proxmoxer import ProxmoxAPI HAS_PROXMOXER = True diff --git a/plugins/modules/cloud/misc/terraform.py b/plugins/modules/cloud/misc/terraform.py index 8c7bd8c70b..8eca14e712 100644 --- a/plugins/modules/cloud/misc/terraform.py +++ b/plugins/modules/cloud/misc/terraform.py @@ -230,11 +230,12 @@ command: import os import json import tempfile -from distutils.version import LooseVersion from ansible.module_utils.six.moves import shlex_quote from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + module = None diff --git a/plugins/modules/cloud/rackspace/rax_cbs.py b/plugins/modules/cloud/rackspace/rax_cbs.py index b543f5979a..abfda419ed 100644 --- a/plugins/modules/cloud/rackspace/rax_cbs.py +++ b/plugins/modules/cloud/rackspace/rax_cbs.py @@ -97,7 +97,7 @@ EXAMPLES = ''' register: my_volume ''' -from distutils.version import LooseVersion +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion try: import pyrax diff --git a/plugins/modules/database/misc/kibana_plugin.py b/plugins/modules/database/misc/kibana_plugin.py index 25d7719353..db5091e400 100644 --- a/plugins/modules/database/misc/kibana_plugin.py +++ b/plugins/modules/database/misc/kibana_plugin.py @@ -117,9 +117,10 @@ state: ''' import os -from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + PACKAGE_STATE_MAP = dict( present="--install", diff --git a/plugins/modules/files/xml.py b/plugins/modules/files/xml.py index ffdb65400c..ae95e9c646 100644 --- a/plugins/modules/files/xml.py +++ b/plugins/modules/files/xml.py @@ -356,9 +356,10 @@ import os import re import traceback -from distutils.version import LooseVersion from io import BytesIO +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + LXML_IMP_ERR = None try: from lxml import etree, objectify diff --git a/plugins/modules/identity/ipa/ipa_subca.py b/plugins/modules/identity/ipa/ipa_subca.py index 3b0d3e8707..387d63c513 100644 --- a/plugins/modules/identity/ipa/ipa_subca.py +++ b/plugins/modules/identity/ipa/ipa_subca.py @@ -74,11 +74,12 @@ subca: type: dict ''' -from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.ipa import IPAClient, ipa_argument_spec from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + class SubCAIPAClient(IPAClient): def __init__(self, module, host, port, protocol): diff --git a/plugins/modules/monitoring/circonus_annotation.py b/plugins/modules/monitoring/circonus_annotation.py index 8543aa00fa..40c7297dd7 100644 --- a/plugins/modules/monitoring/circonus_annotation.py +++ b/plugins/modules/monitoring/circonus_annotation.py @@ -143,7 +143,8 @@ annotation: import json import time import traceback -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion REQUESTS_IMP_ERR = None try: diff --git a/plugins/modules/net_tools/dnsimple.py b/plugins/modules/net_tools/dnsimple.py index ac1b2a1416..d6606cc098 100644 --- a/plugins/modules/net_tools/dnsimple.py +++ b/plugins/modules/net_tools/dnsimple.py @@ -148,9 +148,10 @@ EXAMPLES = ''' RETURN = r"""# """ import traceback -from distutils.version import LooseVersion import re +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + class DNSimpleV1(): """class which uses dnsimple-python < 2""" diff --git a/plugins/modules/notification/mqtt.py b/plugins/modules/notification/mqtt.py index 991114e8ae..6099196102 100644 --- a/plugins/modules/notification/mqtt.py +++ b/plugins/modules/notification/mqtt.py @@ -124,7 +124,8 @@ import os import ssl import traceback import platform -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion HAS_PAHOMQTT = True PAHOMQTT_IMP_ERR = None @@ -207,7 +208,7 @@ def main(): if tls_version: tls_version = tls_map.get(tls_version, ssl.PROTOCOL_SSLv23) else: - if LooseVersion(platform.python_version()) <= "3.5.2": + if LooseVersion(platform.python_version()) <= LooseVersion("3.5.2"): # Specifying `None` on later versions of python seems sufficient to # instruct python to autonegotiate the SSL/TLS connection. On versions # 3.5.2 and lower though we need to specify the version. diff --git a/plugins/modules/notification/sendgrid.py b/plugins/modules/notification/sendgrid.py index 4a63a03db7..2c349064b8 100644 --- a/plugins/modules/notification/sendgrid.py +++ b/plugins/modules/notification/sendgrid.py @@ -124,7 +124,7 @@ EXAMPLES = r''' import os import traceback -from distutils.version import LooseVersion +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion SENDGRID_IMP_ERR = None try: diff --git a/plugins/modules/packaging/os/flatpak.py b/plugins/modules/packaging/os/flatpak.py index 7f3963ad3e..da913b5ac0 100644 --- a/plugins/modules/packaging/os/flatpak.py +++ b/plugins/modules/packaging/os/flatpak.py @@ -152,11 +152,11 @@ stdout: sample: "org.gnome.Calendar/x86_64/stable\tcurrent\norg.gnome.gitg/x86_64/stable\tcurrent\n" ''' -from distutils.version import StrictVersion - from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application" @@ -172,7 +172,7 @@ def install_flat(module, binary, remote, names, method, no_dependencies): id_names.append(name) base_command = [binary, "install", "--{0}".format(method)] flatpak_version = _flatpak_version(module, binary) - if StrictVersion(flatpak_version) < StrictVersion('1.1.3'): + if LooseVersion(flatpak_version) < LooseVersion('1.1.3'): base_command += ["-y"] else: base_command += ["--noninteractive"] @@ -196,7 +196,7 @@ def uninstall_flat(module, binary, names, method): ] command = [binary, "uninstall"] flatpak_version = _flatpak_version(module, binary) - if StrictVersion(flatpak_version) < StrictVersion('1.1.3'): + if LooseVersion(flatpak_version) < LooseVersion('1.1.3'): command += ["-y"] else: command += ["--noninteractive"] diff --git a/plugins/modules/packaging/os/homebrew_cask.py b/plugins/modules/packaging/os/homebrew_cask.py index 6c3de1c9ba..8fe54e3b04 100644 --- a/plugins/modules/packaging/os/homebrew_cask.py +++ b/plugins/modules/packaging/os/homebrew_cask.py @@ -140,7 +140,8 @@ EXAMPLES = ''' import os import re import tempfile -from distutils import version + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion from ansible.module_utils.common.text.converters import to_bytes from ansible.module_utils.basic import AnsibleModule @@ -493,7 +494,7 @@ class HomebrewCask(object): def _brew_cask_command_is_deprecated(self): # The `brew cask` replacements were fully available in 2.6.0 (https://brew.sh/2020/12/01/homebrew-2.6.0/) - return version.LooseVersion(self._get_brew_version()) >= version.LooseVersion('2.6.0') + return LooseVersion(self._get_brew_version()) >= LooseVersion('2.6.0') # /checks ------------------------------------------------------ }}} # commands ----------------------------------------------------- {{{ diff --git a/plugins/modules/packaging/os/mas.py b/plugins/modules/packaging/os/mas.py index dd394b7c43..0afd858add 100644 --- a/plugins/modules/packaging/os/mas.py +++ b/plugins/modules/packaging/os/mas.py @@ -97,9 +97,10 @@ RETURN = r''' # ''' from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_native -from distutils.version import StrictVersion import os +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + class Mas(object): @@ -145,7 +146,7 @@ class Mas(object): # Is the version recent enough? rc, out, err = self.run(['version']) - if rc != 0 or not out.strip() or StrictVersion(out.strip()) < StrictVersion('1.5.0'): + if rc != 0 or not out.strip() or LooseVersion(out.strip()) < LooseVersion('1.5.0'): self.module.fail_json(msg='`mas` tool in version 1.5.0+ needed, got ' + out.strip()) def check_signin(self): diff --git a/plugins/modules/packaging/os/openbsd_pkg.py b/plugins/modules/packaging/os/openbsd_pkg.py index 4299d60ad0..6943569f8d 100644 --- a/plugins/modules/packaging/os/openbsd_pkg.py +++ b/plugins/modules/packaging/os/openbsd_pkg.py @@ -135,10 +135,10 @@ import re import shlex import sqlite3 -from distutils.version import StrictVersion - from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + # Function used for executing commands. def execute_command(cmd, module): @@ -435,7 +435,7 @@ def parse_package_name(names, pkg_spec, module): if pkg_spec[name]['branch']: branch_release = "6.0" - if StrictVersion(platform.release()) < StrictVersion(branch_release): + if LooseVersion(platform.release()) < LooseVersion(branch_release): module.fail_json(msg="package name using 'branch' syntax requires at least OpenBSD %s: %s" % (branch_release, name)) # Sanity check that there are no trailing dashes in flavor. diff --git a/plugins/modules/packaging/os/zypper_repository.py b/plugins/modules/packaging/os/zypper_repository.py index a29650a17e..8483df4c61 100644 --- a/plugins/modules/packaging/os/zypper_repository.py +++ b/plugins/modules/packaging/os/zypper_repository.py @@ -133,8 +133,6 @@ except ImportError: XML_IMP_ERR = traceback.format_exc() HAS_XML = False -from distutils.version import LooseVersion - from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.urls import fetch_url @@ -142,6 +140,8 @@ from ansible.module_utils.common.text.converters import to_text from ansible.module_utils.six.moves import configparser, StringIO from io import open +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + REPO_OPTS = ['alias', 'name', 'priority', 'enabled', 'autorefresh', 'gpgcheck'] diff --git a/plugins/modules/source_control/gitlab/gitlab_branch.py b/plugins/modules/source_control/gitlab/gitlab_branch.py index 2d60aedc19..ce71a00a9b 100644 --- a/plugins/modules/source_control/gitlab/gitlab_branch.py +++ b/plugins/modules/source_control/gitlab/gitlab_branch.py @@ -73,7 +73,8 @@ import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.api import basic_auth_argument_spec -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion GITLAB_IMP_ERR = None try: diff --git a/plugins/modules/source_control/gitlab/gitlab_protected_branch.py b/plugins/modules/source_control/gitlab/gitlab_protected_branch.py index d237784cbc..fe8e98a3f3 100644 --- a/plugins/modules/source_control/gitlab/gitlab_protected_branch.py +++ b/plugins/modules/source_control/gitlab/gitlab_protected_branch.py @@ -73,7 +73,8 @@ import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.api import basic_auth_argument_spec -from distutils.version import LooseVersion + +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion GITLAB_IMP_ERR = None try: diff --git a/plugins/modules/system/dpkg_divert.py b/plugins/modules/system/dpkg_divert.py index 1033f70f14..709d35b865 100644 --- a/plugins/modules/system/dpkg_divert.py +++ b/plugins/modules/system/dpkg_divert.py @@ -158,11 +158,12 @@ diversion: import re import os -from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_bytes, to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + def diversion_state(module, command, path): diversion = dict(path=path, state='absent', divert=None, holder=None) diff --git a/plugins/modules/system/filesystem.py b/plugins/modules/system/filesystem.py index 4f1d6ee0d1..2245d341ce 100644 --- a/plugins/modules/system/filesystem.py +++ b/plugins/modules/system/filesystem.py @@ -115,7 +115,6 @@ EXAMPLES = ''' fstype: vfat ''' -from distutils.version import LooseVersion import os import platform import re @@ -124,6 +123,8 @@ import stat from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + class Device(object): def __init__(self, module, path): diff --git a/plugins/modules/system/pids.py b/plugins/modules/system/pids.py index 9745c31449..1fd8014070 100644 --- a/plugins/modules/system/pids.py +++ b/plugins/modules/system/pids.py @@ -56,13 +56,14 @@ pids: import abc import re -from distutils.version import LooseVersion from os.path import basename from ansible.module_utils import six from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + try: import psutil diff --git a/plugins/modules/system/python_requirements_info.py b/plugins/modules/system/python_requirements_info.py index aae85a2d3e..76be56850d 100644 --- a/plugins/modules/system/python_requirements_info.py +++ b/plugins/modules/system/python_requirements_info.py @@ -122,7 +122,7 @@ import operator HAS_DISTUTILS = False try: import pkg_resources - from distutils.version import LooseVersion + from ansible_collections.community.general.plugins.module_utils.version import LooseVersion HAS_DISTUTILS = True except ImportError: pass diff --git a/plugins/modules/web_infrastructure/htpasswd.py b/plugins/modules/web_infrastructure/htpasswd.py index b15a946448..2eebdfd5b8 100644 --- a/plugins/modules/web_infrastructure/htpasswd.py +++ b/plugins/modules/web_infrastructure/htpasswd.py @@ -95,10 +95,11 @@ EXAMPLES = """ import os import tempfile import traceback -from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.version import LooseVersion + PASSLIB_IMP_ERR = None try: from passlib.apache import HtpasswdFile, htpasswd_context