Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2022-10-04 16:44:00 +0300
committerGitHub <noreply@github.com>2022-10-04 16:44:00 +0300
commit6d0aeac1e166842f2833f4fb64c727cc7f818118 (patch)
treeae74e4ca8c90219fb877821ba3414d4548ccb354 /lib
parent367cdae3b279a5281a56808827af27c8883a4ad4 (diff)
Do not crash templating when filter/test name is not a valid Ansible plugin name (#78913)
* Do not crash templating when filter/test name is not a valid Ansible plugin name. * Store and re-raise KeyError if there was one. Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/template/__init__.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py
index 32e68547358..1498d3f8134 100644
--- a/lib/ansible/template/__init__.py
+++ b/lib/ansible/template/__init__.py
@@ -423,12 +423,13 @@ class JinjaPluginIntercept(MutableMapping):
if not isinstance(key, string_types):
raise ValueError('key must be a string, got %s instead' % type(key))
+ original_exc = None
if key not in self._loaded_builtins:
plugin = None
try:
plugin = self._pluginloader.get(key)
except (AnsibleError, KeyError) as e:
- raise TemplateSyntaxError('Could not load "%s": %s' % (key, to_native(e)), 0)
+ original_exc = e
except Exception as e:
display.vvvv('Unexpected plugin load (%s) exception: %s' % (key, to_native(e)))
raise e
@@ -439,8 +440,11 @@ class JinjaPluginIntercept(MutableMapping):
self._delegatee[key] = plugin.j2_function
self._loaded_builtins.add(key)
- # let it trigger keyerror if we could not find ours or jinja2 one
- func = self._delegatee[key]
+ # raise template syntax error if we could not find ours or jinja2 one
+ try:
+ func = self._delegatee[key]
+ except KeyError as e:
+ raise TemplateSyntaxError('Could not load "%s": %s' % (key, to_native(original_exc or e)), 0)
# if i do have func and it is a filter, it nees wrapping
if self._pluginloader.type == 'filter':