diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 0aacb4b8de..89ba49a867 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -61,6 +61,8 @@ files: maintainers: kellyjonbrazil $filters/list.py: maintainers: vbotka + $filters/path_join_shim.py: + maintainers: felixfontein $filters/time.py: maintainers: resmo $httpapis/: diff --git a/changelogs/fragments/path_join-shim-filter.yml b/changelogs/fragments/path_join-shim-filter.yml new file mode 100644 index 0000000000..f96922203f --- /dev/null +++ b/changelogs/fragments/path_join-shim-filter.yml @@ -0,0 +1,3 @@ +add plugin.filter: + - name: path_join + description: Redirects to ansible.builtin.path_join for ansible-base 2.10 or newer, and provides a compatible implementation for Ansible 2.9 diff --git a/meta/runtime.yml b/meta/runtime.yml index 07049d0b80..3eea76c560 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -601,3 +601,10 @@ plugin_routing: redirect: community.docker.docker_swarm kubevirt: redirect: community.kubevirt.kubevirt + filter: + 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: ansible.builtin.path_join diff --git a/plugins/filter/path_join_shim.py b/plugins/filter/path_join_shim.py new file mode 100644 index 0000000000..9734298a15 --- /dev/null +++ b/plugins/filter/path_join_shim.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# Copyright: (c) 2020-2021, Felix Fontein +# 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, + } diff --git a/tests/integration/targets/filter_path_join_shim/aliases b/tests/integration/targets/filter_path_join_shim/aliases new file mode 100644 index 0000000000..b167317cfe --- /dev/null +++ b/tests/integration/targets/filter_path_join_shim/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller diff --git a/tests/integration/targets/filter_path_join_shim/tasks/main.yml b/tests/integration/targets/filter_path_join_shim/tasks/main.yml new file mode 100644 index 0000000000..5f9eff3d4b --- /dev/null +++ b/tests/integration/targets/filter_path_join_shim/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- name: "Test path_join filter" + assert: + that: + - "['a', 'b'] | community.general.path_join == 'a/b'" + - "['a', '/b'] | community.general.path_join == '/b'" + - "[''] | community.general.path_join == ''"