diff --git a/changelogs/fragments/10892-remove-py2.yml b/changelogs/fragments/10892-remove-py2.yml new file mode 100644 index 0000000000..69904d4777 --- /dev/null +++ b/changelogs/fragments/10892-remove-py2.yml @@ -0,0 +1,7 @@ +minor_changes: + - known_hosts module_utils - drop Python 2 support when parsing output of ``urlparse`` (https://github.com/ansible-collections/community.general/pull/10892). + - aix_inittab - drop Python 2 support for function ``zip`` (https://github.com/ansible-collections/community.general/pull/10892). + - copr - drop support for Python 2 interpreter (https://github.com/ansible-collections/community.general/pull/10892). + - dconf - drop support for Python 2 interpreter (https://github.com/ansible-collections/community.general/pull/10892). + - irc - drop Python 2 support for SSL context creation (https://github.com/ansible-collections/community.general/pull/10892). + - mail - drop Python 2 support for Message-ID domain setting (https://github.com/ansible-collections/community.general/pull/10892). diff --git a/plugins/module_utils/known_hosts.py b/plugins/module_utils/known_hosts.py index 9a17355b4e..9750fa9341 100644 --- a/plugins/module_utils/known_hosts.py +++ b/plugins/module_utils/known_hosts.py @@ -60,17 +60,14 @@ def get_fqdn_and_port(repo_url): elif "://" in repo_url: # this should be something we can parse with urlparse parts = urlparse(repo_url) - # parts[1] will be empty on python2.4 on ssh:// or git:// urls, so - # ensure we actually have a parts[1] before continuing. - if parts[1] != '': - fqdn = parts[1] - if "@" in fqdn: - fqdn = fqdn.split("@", 1)[1] - match = ipv6_re.match(fqdn) - if match: - fqdn, port = match.groups() - elif ":" in fqdn: - fqdn, port = fqdn.split(":")[0:2] + fqdn = parts[1] + if "@" in fqdn: + fqdn = fqdn.split("@", 1)[1] + match = ipv6_re.match(fqdn) + if match: + fqdn, port = match.groups() + elif ":" in fqdn: + fqdn, port = fqdn.split(":")[0:2] return fqdn, port diff --git a/plugins/modules/aix_inittab.py b/plugins/modules/aix_inittab.py index ece4e95547..be845664c9 100644 --- a/plugins/modules/aix_inittab.py +++ b/plugins/modules/aix_inittab.py @@ -114,12 +114,6 @@ name: sample: startmyservice """ -# Import necessary libraries -try: - # python 2 - from itertools import izip -except ImportError: - izip = zip from ansible.module_utils.basic import AnsibleModule @@ -138,7 +132,7 @@ def check_current_entry(module): values = out.split(":") # strip non readable characters as \n values = map(lambda s: s.strip(), values) - existsdict = dict(izip(keys, values)) + existsdict = dict(zip(keys, values)) existsdict.update({'exist': True}) return existsdict diff --git a/plugins/modules/cobbler_sync.py b/plugins/modules/cobbler_sync.py index b1c92a1690..f3a3150917 100644 --- a/plugins/modules/cobbler_sync.py +++ b/plugins/modules/cobbler_sync.py @@ -56,8 +56,6 @@ author: todo: notes: - Concurrently syncing Cobbler is bound to fail with weird errors. - - On Python 2.7.8 and older (such as RHEL7) you may need to tweak the Python behaviour to disable certificate validation. - More information at L(Certificate verification in Python standard library HTTP clients,https://access.redhat.com/articles/2039753). """ EXAMPLES = r""" diff --git a/plugins/modules/cobbler_system.py b/plugins/modules/cobbler_system.py index a1a400928e..7a1bdc4dcb 100644 --- a/plugins/modules/cobbler_system.py +++ b/plugins/modules/cobbler_system.py @@ -79,8 +79,6 @@ author: - Dag Wieers (@dagwieers) notes: - Concurrently syncing Cobbler is bound to fail with weird errors. - - On Python 2.7.8 and older (such as RHEL7) you may need to tweak the Python behaviour to disable certificate validation. - More information at L(Certificate verification in Python standard library HTTP clients,https://access.redhat.com/articles/2039753). """ EXAMPLES = r""" diff --git a/plugins/modules/copr.py b/plugins/modules/copr.py index 940fc0eedd..7f710b58f0 100644 --- a/plugins/modules/copr.py +++ b/plugins/modules/copr.py @@ -129,7 +129,6 @@ def _respawn_dnf(): system_interpreters = ( "/usr/libexec/platform-python", "/usr/bin/python3", - "/usr/bin/python2", "/usr/bin/python", ) interpreter = respawn.probe_interpreters_for_module(system_interpreters, "dnf") diff --git a/plugins/modules/dconf.py b/plugins/modules/dconf.py index 762c443130..c5852284a1 100644 --- a/plugins/modules/dconf.py +++ b/plugins/modules/dconf.py @@ -421,8 +421,7 @@ def main(): msg="%s must be installed and visible from %s." % (glib_module_name, sys.executable)) - interpreters = ['/usr/bin/python3', '/usr/bin/python2', - '/usr/bin/python'] + interpreters = ['/usr/bin/python3', '/usr/bin/python'] interpreter = probe_interpreters_for_module( interpreters, glib_module_name) diff --git a/plugins/modules/github_repo.py b/plugins/modules/github_repo.py index 0971e22878..cf6c34003c 100644 --- a/plugins/modules/github_repo.py +++ b/plugins/modules/github_repo.py @@ -92,8 +92,6 @@ requirements: - PyGithub>=1.54 notes: - For Python 3, PyGithub>=1.54 should be used. - - 'For Python 3.5, PyGithub==1.54 should be used. More information: U(https://pygithub.readthedocs.io/en/latest/changes.html#version-1-54-november-30-2020).' - - 'For Python 2.7, PyGithub==1.45 should be used. More information: U(https://pygithub.readthedocs.io/en/latest/changes.html#version-1-45-december-29-2019).' author: - Álvaro Torres Cogollo (@atorrescogollo) """ diff --git a/plugins/modules/irc.py b/plugins/modules/irc.py index d18c9fd85f..78ac7449f7 100644 --- a/plugins/modules/irc.py +++ b/plugins/modules/irc.py @@ -234,17 +234,10 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k if use_tls: kwargs = {} if validate_certs: - try: - context = ssl.create_default_context() - kwargs["server_hostname"] = server - except AttributeError: - raise Exception('Need at least Python 2.7.9 for SSL certificate validation') + context = ssl.create_default_context() + kwargs["server_hostname"] = server else: - if getattr(ssl, 'PROTOCOL_TLS', None) is not None: - # Supported since Python 2.7.13 - context = ssl.SSLContext(ssl.PROTOCOL_TLS) - else: - context = ssl.SSLContext() + context = ssl.SSLContext(ssl.PROTOCOL_TLS) context.verify_mode = ssl.CERT_NONE irc = context.wrap_socket(irc, **kwargs) irc.connect((server, int(port))) diff --git a/plugins/modules/mail.py b/plugins/modules/mail.py index 7c8bdb69b3..0386bd31b6 100644 --- a/plugins/modules/mail.py +++ b/plugins/modules/mail.py @@ -137,7 +137,6 @@ options: message_id_domain: description: - The domain name to use for the L(Message-ID header, https://en.wikipedia.org/wiki/Message-ID). - - Note that this is only available on Python 3+. On Python 2, this value is ignored. type: str default: ansible version_added: 8.2.0 @@ -352,12 +351,7 @@ def main(): msg['From'] = formataddr((sender_phrase, sender_addr)) msg['Date'] = formatdate(localtime=True) msg['Subject'] = Header(subject, charset) - try: - msg['Message-ID'] = make_msgid(domain=message_id_domain) - except TypeError: - # `domain` is only available in Python 3 - msg['Message-ID'] = make_msgid() - module.warn("The Message-ID domain cannot be set on Python 2; the system's hostname is used") + msg['Message-ID'] = make_msgid(domain=message_id_domain) msg.preamble = "Multipart message" for header in headers: diff --git a/plugins/modules/sl_vm.py b/plugins/modules/sl_vm.py index 8b199f5698..8285028848 100644 --- a/plugins/modules/sl_vm.py +++ b/plugins/modules/sl_vm.py @@ -174,8 +174,6 @@ options: requirements: - softlayer >= 4.1.1 notes: - - If using Python 2.7, you must install C(softlayer-python<=5.7.2). - - If using Python 3.6, you must install C(softlayer-python<=6.0.0). - The C(softlayer-python) library, at version 6.2.6 (from Jan 2025), only supports Python version 3.8, 3.9 and 3.10. author: - Matt Colton (@mcltn) diff --git a/tests/unit/plugins/modules/test_datadog_downtime.py b/tests/unit/plugins/modules/test_datadog_downtime.py index a69e9986d5..bb70007933 100644 --- a/tests/unit/plugins/modules/test_datadog_downtime.py +++ b/tests/unit/plugins/modules/test_datadog_downtime.py @@ -15,7 +15,7 @@ from ansible_collections.community.internal_test_tools.tests.unit.plugins.module from pytest import importorskip -# Skip this test if python 2 so datadog_api_client cannot be installed +# Skip this test if datadog_api_client cannot be installed datadog_api_client = importorskip("datadog_api_client") Downtime = datadog_api_client.v1.model.downtime.Downtime DowntimeRecurrence = datadog_api_client.v1.model.downtime_recurrence.DowntimeRecurrence