1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[5.0.0] Remove Ansible 2.9 / ansible-base 2.10 compatibility code (#4548)

* Remove Ansible 2.9 / ansible-base 2.10 compatibility code.

* Remove path_join shim from BOTMETA.

* Update comment.

* Bump minimally required ansible-core version.
This commit is contained in:
Felix Fontein 2022-04-26 11:51:01 +02:00 committed by GitHub
parent 36a0eca193
commit 1a9b3214fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 44 additions and 276 deletions

View file

@ -108,32 +108,6 @@ stages:
- test: 2
- test: 3
- test: 4
- stage: Sanity_2_10
displayName: Sanity 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Test {0}
testFormat: 2.10/sanity/{0}
targets:
- test: 1
- test: 2
- test: 3
- test: 4
- stage: Sanity_2_9
displayName: Sanity 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Test {0}
testFormat: 2.9/sanity/{0}
targets:
- test: 1
- test: 2
- test: 3
- test: 4
### Units
- stage: Units_devel
displayName: Units devel
@ -188,29 +162,8 @@ stages:
- test: 2.6
- test: 2.7
- test: 3.5
- test: 3.9
- stage: Units_2_10
displayName: Units 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Python {0}
testFormat: 2.10/units/{0}/1
targets:
- test: 2.7
- test: 3.6
- stage: Units_2_9
displayName: Units 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Python {0}
testFormat: 2.9/units/{0}/1
targets:
- test: 2.6
- test: 3.5
- test: 3.9
## Remote
- stage: Remote_devel
@ -285,38 +238,6 @@ stages:
groups:
- 1
- 2
- stage: Remote_2_10
displayName: Remote 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.10/{0}
targets:
- name: OS X 10.11
test: osx/10.11
- name: macOS 10.15
test: macos/10.15
groups:
- 1
- 2
- stage: Remote_2_9
displayName: Remote 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.9/{0}
targets:
- name: RHEL 8.2
test: rhel/8.2
- name: RHEL 7.8
test: rhel/7.8
#- name: FreeBSD 12.0
# test: freebsd/12.0
groups:
- 1
- 2
### Docker
- stage: Docker_devel
@ -389,6 +310,8 @@ stages:
parameters:
testFormat: 2.11/linux/{0}
targets:
- name: Fedora 32
test: fedora32
- name: Fedora 33
test: fedora33
- name: Alpine 3
@ -396,34 +319,6 @@ stages:
groups:
- 2
- 3
- stage: Docker_2_10
displayName: Docker 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.10/linux/{0}
targets:
- name: Fedora 32
test: fedora32
- name: Ubuntu 16.04
test: ubuntu1604
groups:
- 2
- 3
- stage: Docker_2_9
displayName: Docker 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
testFormat: 2.9/linux/{0}
targets:
- name: Fedora 31
test: fedora31
groups:
- 2
- 3
### Community Docker
- stage: Docker_community_devel
@ -485,59 +380,31 @@ stages:
parameters:
nameFormat: Python {0}
testFormat: 2.11/cloud/{0}/1
targets:
- test: 3.6
- stage: Cloud_2_10
displayName: Cloud 2.10
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Python {0}
testFormat: 2.10/cloud/{0}/1
targets:
- test: 3.5
- stage: Cloud_2_9
displayName: Cloud 2.9
dependsOn: []
jobs:
- template: templates/matrix.yml
parameters:
nameFormat: Python {0}
testFormat: 2.9/cloud/{0}/1
targets:
- test: 2.7
- test: 3.5
- stage: Summary
condition: succeededOrFailed()
dependsOn:
- Sanity_devel
- Sanity_2_9
- Sanity_2_10
- Sanity_2_11
- Sanity_2_12
- Sanity_2_13
- Units_devel
- Units_2_9
- Units_2_10
- Units_2_11
- Units_2_12
- Units_2_13
- Remote_devel
- Remote_2_9
- Remote_2_10
- Remote_2_11
- Remote_2_12
- Remote_2_13
- Docker_devel
- Docker_2_9
- Docker_2_10
- Docker_2_11
- Docker_2_12
- Docker_2_13
- Docker_community_devel
- Cloud_devel
- Cloud_2_9
- Cloud_2_10
- Cloud_2_11
- Cloud_2_12
- Cloud_2_13

2
.github/BOTMETA.yml vendored
View file

@ -135,8 +135,6 @@ files:
$filters/json_query.py: {}
$filters/list.py:
maintainers: vbotka
$filters/path_join_shim.py:
maintainers: felixfontein
$filters/random_mac.py: {}
$filters/time.py:
maintainers: resmo

View file

@ -17,9 +17,9 @@ If you encounter abusive behavior violating the [Ansible Code of Conduct](https:
## Tested with Ansible
Tested with the current Ansible 2.9, ansible-base 2.10, ansible-core 2.11, ansible-core 2.12, ansible-core 2.13 releases and the current development version of ansible-core. Ansible versions before 2.9.10 are not supported.
Tested with the current ansible-core 2.11, ansible-core 2.12, ansible-core 2.13 releases and the current development version of ansible-core. Ansible-core versions before 2.11.0 are not supported. This includes all ansible-base 2.10 and Ansible 2.9 releases.
Parts of this collection will not work with ansible-core before 2.12 (this includes ansible-base and Ansible 2.9) on Python 3.12+.
Parts of this collection will not work with ansible-core 2.11 on Python 3.12+.
## External requirements

View file

@ -0,0 +1,12 @@
major_changes:
- The community.general collection no longer supports Ansible 2.9 and ansible-base 2.10. While we take no active measures to prevent usage, we will remove a lot of compatibility code and other compatility measures that will effectively prevent using most content from this collection with Ansible 2.9, and some content of this collection with ansible-base 2.10. Both Ansible 2.9 and ansible-base 2.10 will very soon be End of Life and if you are still using them, you should consider upgrading to ansible-core 2.11 or later as soon as possible (https://github.com/ansible-collections/community.general/pull/4548).
breaking_changes:
- memcached cache plugin - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- redis cache plugin - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- lists_mergeby filter plugin - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- path_join filter plugin shim - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- archive - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- maven_artifact - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- git_config - remove Ansible 2.9 and early ansible-base 2.10 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- java_keystore - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).
- a_module test plugin - remove Ansible 2.9 compatibility code (https://github.com/ansible-collections/community.general/pull/4548).

View file

@ -1,5 +1,5 @@
---
requires_ansible: '>=2.9.10'
requires_ansible: '>=2.11.0'
plugin_routing:
connection:
docker:
@ -624,6 +624,9 @@ plugin_routing:
path_join:
# The ansible.builtin.path_join filter has been added in ansible-base 2.10.
# Since plugin routing is only available since ansible-base 2.10, this
# redirect will be used for ansible-base 2.10 or later, and the included
# path_join filter will be used for Ansible 2.9 or earlier.
# redirect will be used for ansible-base 2.10 or later. This was mostly
# relevant before community.general 5.0.0, when community.general also
# supported Ansible 2.9. Back then, the included path_join filter was used
# for Ansible 2.9 or earlier. Now we only will have the redirect until we
# eventually will deprecate and then remove it.
redirect: ansible.builtin.path_join

View file

@ -176,20 +176,11 @@ class CacheModule(BaseCacheModule):
def __init__(self, *args, **kwargs):
connection = ['127.0.0.1:11211']
try:
super(CacheModule, self).__init__(*args, **kwargs)
if self.get_option('_uri'):
connection = self.get_option('_uri')
self._timeout = self.get_option('_timeout')
self._prefix = self.get_option('_prefix')
except KeyError:
# TODO: remove once we no longer support Ansible 2.9
if not ansible_base_version.startswith('2.9.'):
raise AnsibleError("Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead.")
if C.CACHE_PLUGIN_CONNECTION:
connection = C.CACHE_PLUGIN_CONNECTION.split(',')
self._timeout = C.CACHE_PLUGIN_TIMEOUT
self._prefix = C.CACHE_PLUGIN_PREFIX
super(CacheModule, self).__init__(*args, **kwargs)
if self.get_option('_uri'):
connection = self.get_option('_uri')
self._timeout = self.get_option('_timeout')
self._prefix = self.get_option('_prefix')
if not HAS_MEMCACHE:
raise AnsibleError("python-memcached is required for the memcached fact cache")

View file

@ -99,23 +99,13 @@ class CacheModule(BaseCacheModule):
def __init__(self, *args, **kwargs):
uri = ''
try:
super(CacheModule, self).__init__(*args, **kwargs)
if self.get_option('_uri'):
uri = self.get_option('_uri')
self._timeout = float(self.get_option('_timeout'))
self._prefix = self.get_option('_prefix')
self._keys_set = self.get_option('_keyset_name')
self._sentinel_service_name = self.get_option('_sentinel_service_name')
except KeyError:
# TODO: remove once we no longer support Ansible 2.9
if not ansible_base_version.startswith('2.9.'):
raise AnsibleError("Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead.")
if C.CACHE_PLUGIN_CONNECTION:
uri = C.CACHE_PLUGIN_CONNECTION
self._timeout = float(C.CACHE_PLUGIN_TIMEOUT)
self._prefix = C.CACHE_PLUGIN_PREFIX
self._keys_set = 'ansible_cache_keys'
super(CacheModule, self).__init__(*args, **kwargs)
if self.get_option('_uri'):
uri = self.get_option('_uri')
self._timeout = float(self.get_option('_timeout'))
self._prefix = self.get_option('_prefix')
self._keys_set = self.get_option('_keyset_name')
self._sentinel_service_name = self.get_option('_sentinel_service_name')
if not HAS_REDIS:
raise AnsibleError("The 'redis' python module (version 2.4.5 or newer) is required for the redis fact cache, 'pip install redis'")

View file

@ -15,7 +15,7 @@ DOCUMENTATION = '''
short_description: sends JSON events to syslog
description:
- This plugin logs ansible-playbook and ansible runs to a syslog server in JSON format
- Before 2.9 only environment variables were available for configuration
- Before Ansible 2.9 only environment variables were available for configuration
options:
server:
description: syslog server that will receive the event

View file

@ -16,22 +16,6 @@ from collections import defaultdict
from operator import itemgetter
def merge_hash_wrapper(x, y, recursive=False, list_merge='replace'):
''' Wrapper of the function merge_hash from ansible.utils.vars. Only 2 paramaters are allowed
for Ansible 2.9 and lower.'''
if LooseVersion(ansible_version) < LooseVersion('2.10'):
if list_merge != 'replace' or recursive:
msg = ("Non default options of list_merge(default=replace) or recursive(default=False) "
"are not allowed in Ansible version 2.9 or lower. Ansible version is %s, "
"recursive=%s, and list_merge=%s.")
raise AnsibleFilterError(msg % (ansible_version, recursive, list_merge))
else:
return merge_hash(x, y)
else:
return merge_hash(x, y, recursive, list_merge)
def list_mergeby(x, y, index, recursive=False, list_merge='replace'):
''' Merge 2 lists by attribute 'index'. The function merge_hash from ansible.utils.vars is used.
This function is used by the function lists_mergeby.
@ -44,7 +28,7 @@ def list_mergeby(x, y, index, recursive=False, list_merge='replace'):
msg = "Elements of list arguments for lists_mergeby must be dictionaries. %s is %s"
raise AnsibleFilterError(msg % (elem, type(elem)))
if index in elem.keys():
d[elem[index]].update(merge_hash_wrapper(d[elem[index]], elem, recursive, list_merge))
d[elem[index]].update(merge_hash(d[elem[index]], elem, recursive, list_merge))
return sorted(d.values(), key=itemgetter(index))

View file

@ -1,28 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2020-2021, Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import os.path
def path_join(list):
'''Join list of paths.
This is a minimal shim for ansible.builtin.path_join included in ansible-base 2.10.
This should only be called by Ansible 2.9 or earlier. See meta/runtime.yml for details.
'''
return os.path.join(*list)
class FilterModule(object):
'''Ansible jinja2 filters'''
def filters(self):
return {
'path_join': path_join,
}

View file

@ -440,14 +440,7 @@ class Archive(object):
)
def update_permissions(self):
try:
file_args = self.module.load_file_common_arguments(self.module.params, path=self.destination)
except TypeError:
# The path argument is only supported in Ansible-base 2.10+. Fall back to
# pre-2.10 behavior for older Ansible versions.
self.module.params['path'] = self.destination
file_args = self.module.load_file_common_arguments(self.module.params)
file_args = self.module.load_file_common_arguments(self.module.params, path=self.destination)
self.changed = self.module.set_fs_attributes_if_different(file_args, self.changed)
@property

View file

@ -712,13 +712,7 @@ def main():
except ValueError as e:
module.fail_json(msg=e.args[0])
try:
file_args = module.load_file_common_arguments(module.params, path=dest)
except TypeError:
# The path argument is only supported in Ansible-base 2.10+. Fall back to
# pre-2.10 behavior for older Ansible versions.
module.params['path'] = dest
file_args = module.load_file_common_arguments(module.params)
file_args = module.load_file_common_arguments(module.params, path=dest)
changed = module.set_fs_attributes_if_different(file_args, changed)
if changed:
module.exit_json(state=state, dest=dest, group_id=group_id, artifact_id=artifact_id, version=version, classifier=classifier,

View file

@ -263,13 +263,7 @@ def main():
cmd = args
else:
cmd = args + [new_value]
try: # try using extra parameter from ansible-base 2.10.4 onwards
(rc, out, err) = module.run_command(cmd, cwd=dir, ignore_invalid_cwd=False, expand_user_and_vars=False)
except TypeError:
# @TODO remove try/except when community.general drop support for 2.10.x
if not os.path.isdir(dir):
module.fail_json(msg="Cannot find directory '{0}'".format(dir))
(rc, out, err) = module.run_command(cmd, cwd=dir, expand_user_and_vars=False)
(rc, out, err) = module.run_command(cmd, cwd=dir, ignore_invalid_cwd=False, expand_user_and_vars=False)
if err:
module.fail_json(rc=rc, msg=err, cmd=cmd)

View file

@ -261,13 +261,7 @@ class JavaKeystore:
self.private_key_path = module.params['private_key_path']
def update_permissions(self):
try:
file_args = self.module.load_file_common_arguments(self.module.params, path=self.keystore_path)
except TypeError:
# The path argument is only supported in Ansible-base 2.10+. Fall back to
# pre-2.10 behavior for older Ansible versions.
self.module.params['path'] = self.keystore_path
file_args = self.module.load_file_common_arguments(self.module.params)
file_args = self.module.load_file_common_arguments(self.module.params, path=self.keystore_path)
return self.module.set_fs_attributes_if_different(file_args, False)
def read_certificate_fingerprint(self, cert_format='PEM'):

View file

@ -22,9 +22,6 @@ def a_module(term):
try:
for loader in (action_loader, module_loader):
data = loader.find_plugin(term)
# Ansible 2.9 returns a tuple
if isinstance(data, tuple):
data = data[0]
if data is not None:
return True
return False

View file

@ -64,23 +64,12 @@
register: install_rq0
ignore_errors: true
- name: Assert requirements file was installed (Ansible >2.9)
- name: Assert requirements file was installed
assert:
that:
- install_rq0 is changed
- '"geerlingguy.java" in install_rq0.new_roles'
- '"geerlingguy.php_roles" in install_rq0.new_collections'
when:
- (ansible_version.major != 2 or ansible_version.minor != 9)
- name: Assert requirements file was installed (Ansible 2.9)
assert:
that:
- install_rq0 is failed
- install_rq0 is not changed
when:
- ansible_version.major == 2
- ansible_version.minor == 9
- name: Install from requirements file (again)
community.general.ansible_galaxy_install:

View file

@ -2,7 +2,6 @@
set -eux
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
source virtualenv.sh
# Requirements have to be installed prior to running ansible-playbook

View file

@ -2,7 +2,6 @@
set -eux
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
source virtualenv.sh
# Requirements have to be installed prior to running ansible-playbook

View file

@ -2,7 +2,6 @@
set -eux
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
source virtualenv.sh
# Requirements have to be installed prior to running ansible-playbook

View file

@ -2,7 +2,6 @@
set -eux
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
source virtualenv.sh
# The collection loader ignores paths which have more than one ansible_collections in it.

View file

@ -2,7 +2,6 @@
set -eux
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
source virtualenv.sh
# The collection loader ignores paths which have more than one ansible_collections in it.

View file

@ -25,21 +25,16 @@ pytest.importorskip('redis')
from ansible import constants as C
from ansible.plugins.loader import cache_loader
from ansible.release import __version__ as ansible_version
from ansible_collections.community.general.plugins.cache.redis import CacheModule as RedisCache
def test_redis_cachemodule():
# The _uri option is required for the redis plugin
connection = '127.0.0.1:6379:1'
if ansible_version.startswith('2.9.'):
C.CACHE_PLUGIN_CONNECTION = connection
assert isinstance(cache_loader.get('community.general.redis', **{'_uri': connection}), RedisCache)
def test_redis_cachemodule():
# The _uri option is required for the redis plugin
connection = '[::1]:6379:1'
if ansible_version.startswith('2.9.'):
C.CACHE_PLUGIN_CONNECTION = connection
assert isinstance(cache_loader.get('community.general.redis', **{'_uri': connection}), RedisCache)