From 8173602a34ff7bd0fed7c001a2e2f7dee3d36917 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 18 Apr 2018 09:29:19 +0200 Subject: [PATCH] Add expandvars jinja2 filter (#38805) * Add expandvars jinja2 filter * Add docs * Minor edit --- docs/docsite/rst/user_guide/playbooks_filters.rst | 8 ++++++++ lib/ansible/plugins/filter/core.py | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/docsite/rst/user_guide/playbooks_filters.rst b/docs/docsite/rst/user_guide/playbooks_filters.rst index e28bfce0d39..5831d8a2708 100644 --- a/docs/docsite/rst/user_guide/playbooks_filters.rst +++ b/docs/docsite/rst/user_guide/playbooks_filters.rst @@ -895,6 +895,14 @@ To expand a path containing a tilde (`~`) character (new in version 1.5):: {{ path | expanduser }} +To expand a path containing environment variables:: + + {{ path | expandvars }} + +.. note:: `expandvars` expands local variables; using it on remote paths can lead to errors. + +.. versionadded:: 2.6 + To get the real path of a link (new in version 1.8):: {{ path | realpath }} diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index d8a43016a89..6b39f2fbe1d 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -530,6 +530,7 @@ class FilterModule(object): 'basename': partial(unicode_wrap, os.path.basename), 'dirname': partial(unicode_wrap, os.path.dirname), 'expanduser': partial(unicode_wrap, os.path.expanduser), + 'expandvars': partial(unicode_wrap, os.path.expandvars), 'realpath': partial(unicode_wrap, os.path.realpath), 'relpath': partial(unicode_wrap, os.path.relpath), 'splitext': partial(unicode_wrap, os.path.splitext),