mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 04:11:25 -07:00
Throw a more user-friendly exception during template rendering process.
This commit is contained in:
parent
807e602228
commit
922f61899e
1 changed files with 10 additions and 1 deletions
|
@ -20,6 +20,7 @@ import re
|
||||||
import codecs
|
import codecs
|
||||||
import jinja2
|
import jinja2
|
||||||
from jinja2.runtime import StrictUndefined
|
from jinja2.runtime import StrictUndefined
|
||||||
|
from jinja2.exceptions import TemplateSyntaxError
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
import json
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
|
@ -448,7 +449,15 @@ def template_from_file(basedir, path, vars):
|
||||||
setattr(environment,key.strip(),ast.literal_eval(val.strip()))
|
setattr(environment,key.strip(),ast.literal_eval(val.strip()))
|
||||||
|
|
||||||
environment.template_class = J2Template
|
environment.template_class = J2Template
|
||||||
|
try:
|
||||||
t = environment.from_string(data)
|
t = environment.from_string(data)
|
||||||
|
except TemplateSyntaxError, e:
|
||||||
|
# Throw an exception which includes a more user friendly error message
|
||||||
|
values = {'name': realpath, 'lineno': e.lineno, 'error': str(e)}
|
||||||
|
msg = 'file: %(name)s, line number: %(lineno)s, error: %(error)s' % \
|
||||||
|
values
|
||||||
|
error = errors.AnsibleError(msg)
|
||||||
|
raise error
|
||||||
vars = vars.copy()
|
vars = vars.copy()
|
||||||
try:
|
try:
|
||||||
template_uid = pwd.getpwuid(os.stat(realpath).st_uid).pw_name
|
template_uid = pwd.getpwuid(os.stat(realpath).st_uid).pw_name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue