From a46b500851e5a5f534afdb46d71e7c3506c50c6c Mon Sep 17 00:00:00 2001 From: Jon Hawkesworth Date: Thu, 20 Aug 2015 13:54:54 +0100 Subject: [PATCH] Add win_splitdrive filter for windows users --- docsite/rst/playbooks_filters.rst | 12 ++++++++++++ lib/ansible/plugins/filter/core.py | 1 + 2 files changed, 13 insertions(+) diff --git a/docsite/rst/playbooks_filters.rst b/docsite/rst/playbooks_filters.rst index eb84ecd203b..857fc770ba3 100644 --- a/docsite/rst/playbooks_filters.rst +++ b/docsite/rst/playbooks_filters.rst @@ -342,6 +342,18 @@ To get the last name of a windows style file path (new in version 2.0):: {{ path | win_basename }} +To separate the windows drive letter from the rest of a file path (new in version 2.0):: + + {{ path | win_splitdrive }} + +To get only the windows drive letter + + {{ path | win_splitdrive | first }} + +To get the rest of the path without the drive letter + + {{ path | win_splitdrive | last }} + To get the directory from a path:: {{ path | dirname }} diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 4b8bf2ed354..c0edbe03668 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -254,6 +254,7 @@ class FilterModule(object): 'splitext': partial(unicode_wrap, os.path.splitext), 'win_basename': partial(unicode_wrap, ntpath.basename), 'win_dirname': partial(unicode_wrap, ntpath.dirname), + 'win_splitdrive': partial(unicode_wrap, ntpath.splitdrive), # value as boolean 'bool': bool,