diff --git a/docs/docsite/rst/playbook_guide/playbooks_filters.rst b/docs/docsite/rst/playbook_guide/playbooks_filters.rst index 164d0893c05..39084290bd5 100644 --- a/docs/docsite/rst/playbook_guide/playbooks_filters.rst +++ b/docs/docsite/rst/playbook_guide/playbooks_filters.rst @@ -2021,7 +2021,6 @@ To join one or more path components: .. versionadded:: 2.10 - Manipulating strings ==================== diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 2656faa43cd..1e0c835ae77 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -616,6 +616,7 @@ class FilterModule(object): 'win_dirname': partial(unicode_wrap, ntpath.dirname), 'win_splitdrive': partial(unicode_wrap, ntpath.splitdrive), 'commonpath': commonpath, + 'normpath': partial(unicode_wrap, os.path.normpath), # file glob 'fileglob': fileglob, diff --git a/lib/ansible/plugins/filter/normpath.yml b/lib/ansible/plugins/filter/normpath.yml new file mode 100644 index 00000000000..92ad917d796 --- /dev/null +++ b/lib/ansible/plugins/filter/normpath.yml @@ -0,0 +1,24 @@ +DOCUMENTATION: + name: normpath + author: Shivam Durgbuns + version_added: "2.15" + short_description: Normalize a pathname + description: + - Returns the normalized pathname by collapsing redundant separators and up-level references + options: + _input: + description: A path + type: path + required: true + seealso: + - plugin: ansible.builtin.basename + plugin_type: filter +EXAMPLES: | + + # To get a normalized path(ex. '/foo/bar') from the path(ex. '/foo//bar') + {{ path | normpath }} + +RETURN: + _value: + description: The normalized path from the path given. + type: path \ No newline at end of file