From 2daf527e63bb96ac3c46d3ecdb48723606c4e947 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 9 Sep 2016 15:37:29 +0200 Subject: [PATCH] Fix fileglob filter to work just like fileglob lookup plugin (#17480) The fileglob lookup plugin only returns files, not directories. This is to be expected, as a mixed list would not be very useful in with_fileglob. However the fileglob filter does return anything glob.glob() returns. This change fixes this, so that fileglob returns files (as the name indicates). PS We could also offer a glob filter for thos that would need it ? This relates to comments in issue #17136 and fixes confusion in #17269. --- lib/ansible/plugins/filter/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 8bf829afcb..2ec50f4980 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -126,8 +126,8 @@ def quote(a): return pipes.quote(a) def fileglob(pathname): - ''' return list of matched files for glob ''' - return glob.glob(pathname) + ''' return list of matched regular files for glob ''' + return [ g for g in glob.glob(pathname) if os.path.isfile(g) ] def regex_replace(value='', pattern='', replacement='', ignorecase=False): ''' Perform a `re.sub` returning a string '''