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
This commit is contained in:
parent
9de9633cac
commit
d78da403b6
1 changed files with 9 additions and 2 deletions
|
@ -616,6 +616,7 @@ class Templar:
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
wantlist = kwargs.pop('wantlist', False)
|
wantlist = kwargs.pop('wantlist', False)
|
||||||
allow_unsafe = kwargs.pop('allow_unsafe', C.DEFAULT_ALLOW_UNSAFE_LOOKUPS)
|
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
|
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)
|
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)
|
raise AnsibleUndefinedVariable(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self._fail_on_lookup_errors:
|
if self._fail_on_lookup_errors:
|
||||||
raise AnsibleError("An unhandled exception occurred while running the lookup plugin '%s'. Error was a %s, "
|
msg = u"An unhandled exception occurred while running the lookup plugin '%s'. Error was a %s, original message: %s" % \
|
||||||
"original message: %s" % (name, type(e), e))
|
(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
|
ran = None
|
||||||
|
|
||||||
if ran and not allow_unsafe:
|
if ran and not allow_unsafe:
|
||||||
|
|
Loading…
Reference in a new issue