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:
parent
595d590862
commit
4b6722d938
6 changed files with 49 additions and 0 deletions
2
.github/BOTMETA.yml
vendored
2
.github/BOTMETA.yml
vendored
|
@ -59,6 +59,8 @@ files:
|
|||
maintainers: kellyjonbrazil
|
||||
$filters/list.py:
|
||||
maintainers: vbotka
|
||||
$filters/path_join_shim.py:
|
||||
maintainers: felixfontein
|
||||
$filters/time.py:
|
||||
maintainers: resmo
|
||||
$httpapis/:
|
||||
|
|
3
changelogs/fragments/path_join-shim-filter.yml
Normal file
3
changelogs/fragments/path_join-shim-filter.yml
Normal 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
|
|
@ -611,3 +611,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
|
||||
|
|
28
plugins/filter/path_join_shim.py
Normal file
28
plugins/filter/path_join_shim.py
Normal 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,
|
||||
}
|
2
tests/integration/targets/filter_path_join_shim/aliases
Normal file
2
tests/integration/targets/filter_path_join_shim/aliases
Normal 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
|
|
@ -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 == ''"
|
Loading…
Reference in a new issue