allow 'ignore_missing' for fileglob lookups

pull/47344/head
Philippe Kueck 6 years ago
parent 2fedde6356
commit 37c616dc76
No known key found for this signature in database
GPG Key ID: E10E57D62DB57A3B

@ -0,0 +1,3 @@
---
minor_changes:
- fileglob - add 'ignore_missing' to suppress 'Unable to find...' warnings

@ -16,6 +16,11 @@ DOCUMENTATION = """
_terms:
description: path(s) of files to read
required: True
ignore_missing:
description: Flag to control whether or not no matches found return a warning
type: boolean
default: False
version_added: "2.14"
notes:
- Patterns are only supported on files, not directory/paths.
- Matching is against local system files on the Ansible controller.
@ -57,12 +62,14 @@ class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
self.set_options(direct=kwargs)
ret = []
for term in terms:
term_file = os.path.basename(term)
found_paths = []
if term_file != term:
found_paths.append(self.find_file_in_search_path(variables, 'files', os.path.dirname(term)))
found_paths.append(self.find_file_in_search_path(variables, 'files', os.path.dirname(term), ignore_missing=self.get_option('ignore_missing')))
else:
# no dir, just file, so use paths and 'files' paths instead
if 'ansible_search_path' in variables:

Loading…
Cancel
Save