diff --git a/changelogs/fragments/disutils.version.yml b/changelogs/fragments/disutils.version.yml new file mode 100644 index 000000000..48f69e4bd --- /dev/null +++ b/changelogs/fragments/disutils.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." diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py new file mode 100644 index 000000000..73934eb0c --- /dev/null +++ b/plugins/module_utils/version.py @@ -0,0 +1,19 @@ +# -*- 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 # noqa: F401 +except ImportError: + try: + from distutils.version import LooseVersion # noqa: F401 + except ImportError as exc: + raise_from(ImportError('To use this plugin or module with ansible-core < 2.11, you need to use Python < 3.12 with distutils.version present'), exc) diff --git a/plugins/modules/vmware_category.py b/plugins/modules/vmware_category.py index 78e6ee18b..f50b9e691 100644 --- a/plugins/modules/vmware_category.py +++ b/plugins/modules/vmware_category.py @@ -151,10 +151,9 @@ } ''' -from distutils.version import LooseVersion - from ansible.module_utils._text import to_native from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.vmware.plugins.module_utils.version import LooseVersion from ansible_collections.community.vmware.plugins.module_utils.vmware import connect_to_api from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient diff --git a/plugins/modules/vmware_vc_infraprofile_info.py b/plugins/modules/vmware_vc_infraprofile_info.py index 58f515fbd..9e27d17fb 100644 --- a/plugins/modules/vmware_vc_infraprofile_info.py +++ b/plugins/modules/vmware_vc_infraprofile_info.py @@ -149,8 +149,8 @@ } ''' -from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule +from ansible_collections.community.vmware.plugins.module_utils.version import LooseVersion from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi import json