diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 555ab45..929a3e3 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -99,13 +99,13 @@ import json import re import socket from collections import defaultdict -from distutils.version import LooseVersion from ansible.errors import AnsibleError from ansible.module_utils._text import to_native from ansible.module_utils.parsing.convert_bool import boolean from ansible.module_utils.six import iteritems from ansible.plugins.inventory import BaseInventoryPlugin +from ansible_collections.xoxys.general.plugins.module_utils.version import LooseVersion try: from proxmoxer import ProxmoxAPI diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py new file mode 100644 index 0000000..7334182 --- /dev/null +++ b/plugins/module_utils/version.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2021, Felix Fontein +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later +"""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 # noqa: F401, pylint: disable=unused-import + 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/iptables_raw.py b/plugins/modules/iptables_raw.py index 5f0b160..255e473 100644 --- a/plugins/modules/iptables_raw.py +++ b/plugins/modules/iptables_raw.py @@ -216,6 +216,7 @@ from collections import defaultdict from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import json +from ansible_collections.xoxys.general.plugins.module_utils.version import LooseVersion # Genereates a diff dictionary from an old and new table dump. @@ -357,7 +358,6 @@ class Iptables: # Checks if iptables is installed and if we have a correct version. def _check_compatibility(self): - from distutils.version import StrictVersion cmd = [self.bins['iptables'], '--version'] rc, stdout, stderr = Iptables.module.run_command(cmd, check_rc=False) if rc == 0: @@ -366,7 +366,7 @@ class Iptables: version = result.group(1) # CentOS 5 ip6tables (v1.3.x) doesn't support comments, # which means it cannot be used with this module. - if StrictVersion(version) < StrictVersion('1.4'): + if LooseVersion(version) < LooseVersion('1.4'): Iptables.module.fail_json( msg="This module isn't compatible with ip6tables versions older than 1.4.x" ) diff --git a/plugins/modules/proxmox_kvm.py b/plugins/modules/proxmox_kvm.py index 268e21c..1c73987 100644 --- a/plugins/modules/proxmox_kvm.py +++ b/plugins/modules/proxmox_kvm.py @@ -813,9 +813,9 @@ import string import time import traceback from collections import defaultdict -from distutils.version import LooseVersion from ansible.module_utils.six.moves.urllib.parse import quote +from ansible_collections.xoxys.general.plugins.module_utils.version import LooseVersion try: from proxmoxer import ProxmoxAPI diff --git a/tests/unit/plugins/inventory/test_proxmox.py b/tests/unit/plugins/inventory/test_proxmox.py index 9696aed..3beb0b3 100644 --- a/tests/unit/plugins/inventory/test_proxmox.py +++ b/tests/unit/plugins/inventory/test_proxmox.py @@ -10,7 +10,6 @@ import pytest proxmox = pytest.importorskip("proxmoxer") -from ansible.errors import AnsibleError, AnsibleParserError # noqa from plugins.inventory.proxmox import InventoryModule