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

Add path_join compatibility shim (#2172)

* Add path_join compatibility shim.

* Add myself as maintainer.
This commit is contained in:
Felix Fontein 2021-04-08 07:49:57 +02:00 committed by GitHub
parent 595d590862
commit 4b6722d938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 0 deletions

2
.github/BOTMETA.yml vendored
View file

@ -59,6 +59,8 @@ files:
maintainers: kellyjonbrazil maintainers: kellyjonbrazil
$filters/list.py: $filters/list.py:
maintainers: vbotka maintainers: vbotka
$filters/path_join_shim.py:
maintainers: felixfontein
$filters/time.py: $filters/time.py:
maintainers: resmo maintainers: resmo
$httpapis/: $httpapis/:

View file

@ -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

View file

@ -611,3 +611,10 @@ plugin_routing:
redirect: community.docker.docker_swarm redirect: community.docker.docker_swarm
kubevirt: kubevirt:
redirect: community.kubevirt.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

View file

@ -0,0 +1,28 @@
# -*- 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

@ -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

View file

@ -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 == ''"