From 4059904a18fef4a3e3b4c139f12c1367b39ed4d7 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 29 Jun 2015 15:39:57 -0500 Subject: [PATCH] Add splitext filter --- docsite/rst/playbooks_filters.rst | 5 +++++ lib/ansible/plugins/filter/core.py | 1 + 2 files changed, 6 insertions(+) diff --git a/docsite/rst/playbooks_filters.rst b/docsite/rst/playbooks_filters.rst index 4e35cee522e..10ea62f6a25 100644 --- a/docsite/rst/playbooks_filters.rst +++ b/docsite/rst/playbooks_filters.rst @@ -350,6 +350,11 @@ To get the relative path of a link, from a start point (new in version 1.7):: {{ path | relpath('/etc') }} +To get the root and extension of a path or filename (new in version 2.0):: + + # with path == 'nginx.conf' the return would be ('nginx', '.conf') + {{ path | splitext }} + To work with Base64 encoded strings:: {{ encoded | b64decode }} diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index a717c5bd817..e8e3e17f775 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -316,6 +316,7 @@ class FilterModule(object): 'expanduser': partial(unicode_wrap, os.path.expanduser), 'realpath': partial(unicode_wrap, os.path.realpath), 'relpath': partial(unicode_wrap, os.path.relpath), + 'splitext': partial(unicode_wrap, os.path.splitext), # failure testing 'failed' : failed,