allow user control of lookup error behaviour (#35932)

* allow user control of lookup error behaviour

this does not affect undefined vars, only other exceptions raised by a lookup

i.e lookup('file' ..) not finding a file
pull/37940/merge
Brian Coca 7 years ago committed by GitHub
parent 9de9633cac
commit d78da403b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -616,6 +616,7 @@ class Templar:
if instance is not None:
wantlist = kwargs.pop('wantlist', False)
allow_unsafe = kwargs.pop('allow_unsafe', C.DEFAULT_ALLOW_UNSAFE_LOOKUPS)
errors = kwargs.pop('errors', 'strict')
from ansible.utils.listify import listify_lookup_plugin_terms
loop_terms = listify_lookup_plugin_terms(terms=args, templar=self, loader=self._loader, fail_on_undefined=True, convert_bare=False)
@ -626,8 +627,14 @@ class Templar:
raise AnsibleUndefinedVariable(e)
except Exception as e:
if self._fail_on_lookup_errors:
raise AnsibleError("An unhandled exception occurred while running the lookup plugin '%s'. Error was a %s, "
"original message: %s" % (name, type(e), e))
msg = u"An unhandled exception occurred while running the lookup plugin '%s'. Error was a %s, original message: %s" % \
(name, type(e), to_text(e))
if errors == 'warn':
display.warning(msg)
elif errors == 'ignore':
display.log(msg)
else:
raise AnsibleError(to_native(msg))
ran = None
if ran and not allow_unsafe:

Loading…
Cancel
Save