Skip to content

Instantly share code, notes, and snippets.

@bcoca
Created April 14, 2020 17:00
Show Gist options
  • Save bcoca/cb4b35725a4696dd5669749838debd0b to your computer and use it in GitHub Desktop.
Save bcoca/cb4b35725a4696dd5669749838debd0b 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..e217793087 100644
--- a/lib/ansible/plugins/lookup/fileglob.py
+++ b/lib/ansible/plugins/lookup/fileglob.py
@@ -58,7 +58,17 @@ 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 term_file != term:
+ dwimmed_path = 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)]
+ dwimmed_path = [[os.path.join(p, 'files'), p] for p in paths]
+ print(dwimmed_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment