Skip to content

Instantly share code, notes, and snippets.

@bcoca
Created April 14, 2020 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcoca/64c4b1cc0668eefd9d5cf7f9e6def94d to your computer and use it in GitHub Desktop.
Save bcoca/64c4b1cc0668eefd9d5cf7f9e6def94d to your computer and use it in GitHub Desktop.
diff --git a/lib/ansible/plugins/lookup/fileglob.py b/lib/ansible/plugins/lookup/fileglob.py
index 91442dda5e..2460ba15dd 100644
--- a/lib/ansible/plugins/lookup/fileglob.py
+++ b/lib/ansible/plugins/lookup/fileglob.py
@@ -58,8 +58,22 @@ class LookupModule(LookupBase):
ret = []
for term in terms:
term_file = os.path.basename(term)
- dwimmed_path = self.find_file_in_search_path(variables, 'files', os.path.dirname(term))
- if dwimmed_path:
+ found_paths = []
+ if term_file != term:
+ found_paths.append(self.find_file_in_search_path(variables, 'files', os.path.dirname(term)))
+ else:
+ # no dir, just file, so use paths and 'files' paths instead
+ if 'ansible_search_path' in variables:
+ paths = variables['ansible_search_path']
+ else:
+ paths = [self.get_basedir(variables)]
+ for p in paths:
+ found_paths.append(os.path.join(p, 'files'))
+ found_paths.append(p)
+
+ for dwimmed_path in found_paths:
globbed = glob.glob(to_bytes(os.path.join(dwimmed_path, term_file), errors='surrogate_or_strict'))
ret.extend(to_text(g, errors='surrogate_or_strict') for g in globbed if os.path.isfile(g))
+ if ret:
+ break
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment