Templar: remove _fail_on_{lookup,filter}_errors (#73785)
Both were added in 62d79568be
and never
used, always being set to True.
This commit is contained in:
parent
3bc2e7783c
commit
57d661e96f
2 changed files with 108 additions and 120 deletions
2
changelogs/fragments/Templar-remove-fail-on-errors.yml
Normal file
2
changelogs/fragments/Templar-remove-fail-on-errors.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- Templar - remove ``_fail_on_lookup_errors`` and ``_fail_on_filter_errors`` instance variables that were never used. (https://github.com/ansible/ansible/pull/73785)
|
|
@ -648,10 +648,6 @@ class Templar:
|
||||||
self._cached_result = {}
|
self._cached_result = {}
|
||||||
self._basedir = loader.get_basedir() if loader else './'
|
self._basedir = loader.get_basedir() if loader else './'
|
||||||
|
|
||||||
# flags to determine whether certain failures during templating
|
|
||||||
# should result in fatal errors being raised
|
|
||||||
self._fail_on_lookup_errors = True
|
|
||||||
self._fail_on_filter_errors = True
|
|
||||||
self._fail_on_undefined_errors = C.DEFAULT_UNDEFINED_VAR_BEHAVIOR
|
self._fail_on_undefined_errors = C.DEFAULT_UNDEFINED_VAR_BEHAVIOR
|
||||||
|
|
||||||
environment_class = AnsibleNativeEnvironment if USE_JINJA2_NATIVE else AnsibleEnvironment
|
environment_class = AnsibleNativeEnvironment if USE_JINJA2_NATIVE else AnsibleEnvironment
|
||||||
|
@ -807,14 +803,13 @@ class Templar:
|
||||||
if fail_on_undefined is None:
|
if fail_on_undefined is None:
|
||||||
fail_on_undefined = self._fail_on_undefined_errors
|
fail_on_undefined = self._fail_on_undefined_errors
|
||||||
|
|
||||||
try:
|
|
||||||
if convert_bare:
|
if convert_bare:
|
||||||
variable = self._convert_bare_variable(variable)
|
variable = self._convert_bare_variable(variable)
|
||||||
|
|
||||||
if isinstance(variable, string_types):
|
if isinstance(variable, string_types):
|
||||||
result = variable
|
if not self.is_possibly_template(variable):
|
||||||
|
return variable
|
||||||
|
|
||||||
if self.is_possibly_template(variable):
|
|
||||||
# Check to see if the string we are trying to render is just referencing a single
|
# Check to see if the string we are trying to render is just referencing a single
|
||||||
# var. In this case we don't want to accidentally change the type of the variable
|
# var. In this case we don't want to accidentally change the type of the variable
|
||||||
# to a string by using the jinja template renderer. We just want to pass it.
|
# to a string by using the jinja template renderer. We just want to pass it.
|
||||||
|
@ -841,9 +836,10 @@ class Templar:
|
||||||
).encode('utf-8')
|
).encode('utf-8')
|
||||||
)
|
)
|
||||||
sha1_hash = variable_hash.hexdigest() + options_hash.hexdigest()
|
sha1_hash = variable_hash.hexdigest() + options_hash.hexdigest()
|
||||||
if cache and sha1_hash in self._cached_result:
|
|
||||||
result = self._cached_result[sha1_hash]
|
if sha1_hash in self._cached_result:
|
||||||
else:
|
return self._cached_result[sha1_hash]
|
||||||
|
|
||||||
result = self.do_template(
|
result = self.do_template(
|
||||||
variable,
|
variable,
|
||||||
preserve_trailing_newlines=preserve_trailing_newlines,
|
preserve_trailing_newlines=preserve_trailing_newlines,
|
||||||
|
@ -864,9 +860,7 @@ class Templar:
|
||||||
result = eval_results[0]
|
result = eval_results[0]
|
||||||
if unsafe:
|
if unsafe:
|
||||||
result = wrap_var(result)
|
result = wrap_var(result)
|
||||||
else:
|
|
||||||
# FIXME: if the safe_eval raised an error, should we do something with it?
|
# FIXME: if the safe_eval raised an error, should we do something with it?
|
||||||
pass
|
|
||||||
|
|
||||||
# we only cache in the case where we have a single variable
|
# we only cache in the case where we have a single variable
|
||||||
# name, to make sure we're not putting things which may otherwise
|
# name, to make sure we're not putting things which may otherwise
|
||||||
|
@ -903,12 +897,6 @@ class Templar:
|
||||||
else:
|
else:
|
||||||
return variable
|
return variable
|
||||||
|
|
||||||
except AnsibleFilterError:
|
|
||||||
if self._fail_on_filter_errors:
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
return variable
|
|
||||||
|
|
||||||
def is_template(self, data):
|
def is_template(self, data):
|
||||||
'''lets us know if data has a template'''
|
'''lets us know if data has a template'''
|
||||||
if isinstance(data, string_types):
|
if isinstance(data, string_types):
|
||||||
|
@ -1022,7 +1010,6 @@ class Templar:
|
||||||
raise e
|
raise e
|
||||||
except AnsibleLookupError as e:
|
except AnsibleLookupError as e:
|
||||||
# lookup handled error but still decided to bail
|
# lookup handled error but still decided to bail
|
||||||
if self._fail_on_lookup_errors:
|
|
||||||
msg = 'Lookup failed but the error is being ignored: %s' % to_native(e)
|
msg = 'Lookup failed but the error is being ignored: %s' % to_native(e)
|
||||||
if errors == 'warn':
|
if errors == 'warn':
|
||||||
display.warning(msg)
|
display.warning(msg)
|
||||||
|
@ -1033,7 +1020,6 @@ class Templar:
|
||||||
return [] if wantlist else None
|
return [] if wantlist else None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# errors not handled by lookup
|
# errors not handled by lookup
|
||||||
if self._fail_on_lookup_errors:
|
|
||||||
msg = u"An unhandled exception occurred while running the lookup plugin '%s'. Error was a %s, original message: %s" % \
|
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))
|
(name, type(e), to_text(e))
|
||||||
if errors == 'warn':
|
if errors == 'warn':
|
||||||
|
|
Loading…
Reference in a new issue