From 37c616dc76d9ebc3cbf0285a22e55f0e4db4185e Mon Sep 17 00:00:00 2001 From: Philippe Kueck Date: Mon, 19 Nov 2018 12:18:13 +0100 Subject: [PATCH] allow 'ignore_missing' for fileglob lookups --- changelogs/fragments/47344-ignore_missing_fileglob.yml | 3 +++ lib/ansible/plugins/lookup/fileglob.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/47344-ignore_missing_fileglob.yml diff --git a/changelogs/fragments/47344-ignore_missing_fileglob.yml b/changelogs/fragments/47344-ignore_missing_fileglob.yml new file mode 100644 index 00000000000..b64a99dd642 --- /dev/null +++ b/changelogs/fragments/47344-ignore_missing_fileglob.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - fileglob - add 'ignore_missing' to suppress 'Unable to find...' warnings diff --git a/lib/ansible/plugins/lookup/fileglob.py b/lib/ansible/plugins/lookup/fileglob.py index b1ee05a2f9a..9d960b45838 100644 --- a/lib/ansible/plugins/lookup/fileglob.py +++ b/lib/ansible/plugins/lookup/fileglob.py @@ -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: