From 89e73c123f1d242560737d38bbd020a7f512b5e4 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 11 Feb 2013 23:34:52 +0100 Subject: [PATCH] Fix tilde expansion for fileglob Use common suffix to determine what part of original term to keep and how much of the full path to combine to get a usable filename. --- lib/ansible/runner/lookup_plugins/fileglob.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/runner/lookup_plugins/fileglob.py b/lib/ansible/runner/lookup_plugins/fileglob.py index a42ffcb2741..70d202c987c 100644 --- a/lib/ansible/runner/lookup_plugins/fileglob.py +++ b/lib/ansible/runner/lookup_plugins/fileglob.py @@ -31,7 +31,11 @@ class LookupModule(object): for term in terms: dwimterms = utils.path_dwim(self.basedir, term) # This skips whatever prefix the dwim added, leaving just the filename for the item - dwim_prefix_len = len(dwimterms) - len(term) - ret.extend([ f[dwim_prefix_len:] + i = -1 + while dwimterms[i] == term[i] and -i < len(term) and -i < len(dwimterms): + i = i - 1 + orig_prefix_len = i + 1 + dwim_prefix_len = len(dwimterms) + i + 1 + ret.extend([ term[:orig_prefix_len] + f[dwim_prefix_len:] for f in glob.glob(dwimterms) if os.path.isfile(f) ]) return ret