Line number is missing in Jinja2 syntax errors
Background: I am using file.managed state to provision a file. It's a Jinja template. I have a syntax error and salt myminion state.highstate gives me
...
----------
ID: /etc/myfile.conf
Function: file.managed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1723, in call
**cdata['kwargs'])
File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1650, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 1635, in managed
**kwargs
File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 3940, in check_managed_changes
**kwargs)
File "/usr/lib/python2.7/dist-packages/salt/modules/file.py", line 3610, in get_managed
**kwargs)
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 178, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 384, in render_jinja_tmpl
buf=tmplstr)
SaltRenderError: Jinja variable 'salt.utils.context.NamespacedDictWrapper object' has no attribute 'log-server'
Started: 02:07:49.563765
Duration: 30.776 ms
Changes:
...
Expected: That I somewhere in that error message get the line number in my Jinja template where this error happens.
What happens: It's missing.
Proposed solution: Somewhere add the Jinja template line where this error happens.
@terminalmage i believe that I remember you working on this at some point.
Could you comment on this?
Thanks! Daniel
@gtmanfred I think you're mistaken. But I can still take a look.
@JensRantil Please provide a versions report for the minion (i.e. salt minion_name test.versions_report).
@JensRantil It's also not clear what you mean by "syntax error". Is this log-server attribute some Jinja variable that hasn't been defined?
@terminalmage
Please provide a versions report for the minion (i.e. salt minion_name test.versions_report).
system-0:
Salt Version:
Salt: 2016.3.0
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.6
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: 0.21.1
Mako: 0.7.0
msgpack-pure: Not Installed
msgpack-python: 0.3.0
mysql-python: 1.2.3
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.3 (default, Jun 22 2015, 19:33:41)
python-gnupg: Not Installed
PyYAML: 3.10
PyZMQ: 14.0.1
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.4
System Versions:
dist: Ubuntu 12.04 precise
machine: x86_64
release: 3.2.0-113-virtual
system: Linux
version: Ubuntu 12.04 precise
It's also not clear what you mean by "syntax error". Is this log-server attribute some Jinja variable that hasn't been defined?
Ish. log-server is a key in the pillardictionary that was missing. Essentially I had {{ pillar['log-server'] }} in the jinja template.
OK, thanks for the additional information.
This looks to be a duplicate of https://github.com/saltstack/salt/issues/21298
@jdshewey Nice find! I'll close this.