Jinja2 templates and undefined variables

466 views
Skip to first unread message

NotSqrt

unread,
Aug 16, 2012, 12:14:29 PM8/16/12
to salt-...@googlegroups.com
Hello,

I've had problems experimenting with Pillar : I had configured it badly, so my templates were using empty variables resulting in a rather bad situation on my test server ...

A few things in the tutorial/documentation that would have helped me : 
  • a more visible presence of the command pillar.data
  • some explanations on the option test, for commands like state.highstate
I ended up using the UndefinedException from Jinja to track undefined variables / keys in dict, and raise errors. (see git diff as attachment).

It might be useful for someone else!

Thanks
jinja_exception.patch

Thomas S Hatch

unread,
Aug 16, 2012, 5:05:23 PM8/16/12
to salt-...@googlegroups.com
Hi NoSqrt,

This is good info, and a good patch. I think that we need to have a more clear system for debugging pillar, I added an issue to github (https://github.com/saltstack/salt/issues/1838) for it and I would be happy to merge this patch and probably some more systems to make this clearer.

Can I persuade you to make a pull request on github so we can better track the changes?

Not Sqrt

unread,
Aug 17, 2012, 3:02:17 AM8/17/12
to salt-...@googlegroups.com
Hello,

No problem for a pull request, I'll look into it in the next few days.
My patch might be too strict : one may want to be able to use undefined variables in templates ! So I'm not 100% certain that it's a good idea to make this mandatory.
There may be a way to make this optional ?

2012/8/16 Thomas S Hatch <that...@gmail.com>

Thomas S Hatch

unread,
Aug 17, 2012, 1:12:34 PM8/17/12
to salt-...@googlegroups.com
Good call, I think that what we really need is to make it more trackable, so that an undefined variable would log errors but maybe not halt the renderer
Reply all
Reply to author
Forward
0 new messages