diff options
author | cos <cos> | 2024-04-20 09:49:20 +0200 |
---|---|---|
committer | cos <cos> | 2024-04-20 09:49:20 +0200 |
commit | 4a8cba9f5881c02efe11c043d91b22325a591579 (patch) | |
tree | 6c52b3df5315ddae440dd6d6d2526f0481aecee2 /lib/ansible/plugins/lookup/file.py | |
parent | 3280e8181e83872988933ea71b89ae891749a872 (diff) | |
parent | bbed591285e1882d05198e518f75873af58939f5 (diff) | |
download | debian-ansible-core-debian/failed-recreation-attempt.zip |
Update upstream source from recreated 2.16.5 importdebian/failed-recreation-attempt
Diffstat (limited to 'lib/ansible/plugins/lookup/file.py')
-rw-r--r-- | lib/ansible/plugins/lookup/file.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py index fa9191ee..25946b25 100644 --- a/lib/ansible/plugins/lookup/file.py +++ b/lib/ansible/plugins/lookup/file.py @@ -28,11 +28,14 @@ DOCUMENTATION = """ notes: - if read in variable context, the file can be interpreted as YAML if the content is valid to the parser. - this lookup does not understand 'globbing', use the fileglob lookup instead. + seealso: + - ref: playbook_task_paths + description: Search paths used for relative files. """ EXAMPLES = """ - ansible.builtin.debug: - msg: "the value of foo.txt is {{lookup('ansible.builtin.file', '/etc/foo.txt') }}" + msg: "the value of foo.txt is {{ lookup('ansible.builtin.file', '/etc/foo.txt') }}" - name: display multiple file contents ansible.builtin.debug: var=item @@ -50,9 +53,9 @@ RETURN = """ elements: str """ -from ansible.errors import AnsibleError, AnsibleParserError +from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleLookupError from ansible.plugins.lookup import LookupBase -from ansible.module_utils._text import to_text +from ansible.module_utils.common.text.converters import to_text from ansible.utils.display import Display display = Display() @@ -67,11 +70,10 @@ class LookupModule(LookupBase): for term in terms: display.debug("File lookup term: %s" % term) - # Find the file in the expected search path - lookupfile = self.find_file_in_search_path(variables, 'files', term) - display.vvvv(u"File lookup using %s as file" % lookupfile) try: + lookupfile = self.find_file_in_search_path(variables, 'files', term, ignore_missing=True) + display.vvvv(u"File lookup using %s as file" % lookupfile) if lookupfile: b_contents, show_data = self._loader._get_file_contents(lookupfile) contents = to_text(b_contents, errors='surrogate_or_strict') @@ -81,8 +83,9 @@ class LookupModule(LookupBase): contents = contents.rstrip() ret.append(contents) else: - raise AnsibleParserError() - except AnsibleParserError: - raise AnsibleError("could not locate file in lookup: %s" % term) + # TODO: only add search info if abs path? + raise AnsibleOptionsError("file not found, use -vvvvv to see paths searched") + except AnsibleError as e: + raise AnsibleLookupError("The 'file' lookup had an issue accessing the file '%s'" % term, orig_exc=e) return ret |