5 ms·
Jinja 2.10
- the_mitsuhiko 9y agoThe native environment should help ansible users a lot. As far as I know this will unblock quite a few issues that are currently open against ansible. What it does: http://jinja.pocoo.org/docs/2.10/nativetypes/ http://jinja.pocoo.org/docs/2.10/nativetypes/
- yeukhon 9y agoYeah. It has been a major pain for a lot of folks. See https://github.com/pallets/jinja/pull/708 https://github.com/pallets/jinja/pull/708 and its reference issues.
- koolba 9y agoWhat’s a sample use case for this? A Python-ish VM to eval user supplied expressions?
- the_mitsuhiko 9y agoAnsible generates out a lot of yaml and uses jinja for expressions.
- xorcist 9y agoWhile the changes in Jinja are welcome, maybe, just maybe, Ansible should consider not using yaml for absolutely everything. There can be more sensible ways to store data sometimes. Just saying.
- Jedd 9y ago> ... maybe, Ansible should consider not using yaml for absolutely everything. Maybe. But what problems with Ansible are you trying to solve by using additional, and perhaps domain specific, languages? I haven't used Ansible, but I do use SaltStack, which also relies on YAML, and also uses Jinja, hence my interest here. SaltStack, and I'm assuming Ansible can do this too, will happily use whatever you want, even raw python, as state (configuration) files, so long as they can generate yaml. This is not as inelegant as it sounds :) -- it means configuration length & complexity can be represented by (or hidden behind) short, palatable algorithms. As soon as the suggestion is made to introduce yet another DSL to a system, you end up with holy wars about which one, and then a total mess trying to integrate and support both. Anyway, if you don't want to use YAML / Jinja, then eschew SaltStack, Ansible etc in favour of Chef, Puppet, SCCM, etc.
- mattbillenstein 9y agoYou can use mako in salt, I haven't had any issues with it at all.
- the_mitsuhiko 9y agoMako and Jinja (until this release) really did not differ all that much with regards to this feature. However the ansible community outlined enough reasons for why they are interested in this.
- yeukhon 9y agoThe most common problem arises when your Ansible module's argument/option expects an integer for example, but because jinja (using filter such as arg="{{ my_var | do_something }}" returns a string, so the spec of your module will reject the input! This is a hit or a miss in implementation. Dict, list, boolean, float, int, str are all acceptable primitives that must be handled properly.
- INTPenis 9y agoImagine an xmlrpc client module that could use any xmlrpc API and you wouldn't need one module for every task in the API. Which is the case now in the ansible modules. But the module can't send an actual integer to the API if the API expects an int. It always came out as a string. This is due to the issue with native types. You could add logic to recognize integers and let users specify if they want integer conversion of values or not but that's a lot of extra crud for something that could be very simple.
- mattbillenstein 9y agoI must say, I almost always try to swap in Mako for Jinja -- instead of learning yet another DSL for templating, I can just use a very good language I already know in my templates: Python.
- deleted 9y ago[deleted]
- iamgopal 9y agoYou know Jinja compiles template in to python code, right ?
- mattbillenstein 9y agoYeah, what is your point?
- sigjuice 9y agoFor those of us unfamiliar with this stuff, would it be accurate think of a "template engine" as a sophisticated "printf"?
- praneshp 9y agoLittle bit more than a single printf. For example you can do loops. https://stackoverflow.com/questions/17691838/range-in-jinja2-inside-a-for-loop https://stackoverflow.com/questions/17691838/range-in-jinja2...
- dangerbird2 9y agoA templating engine does a few things differently than printf. Typically, it will compile into an intermediate version, for scripting languages like python as a module or object in the language. Most importantly, it escapes the input to prevent arbitrary HTML injection, for example a user inserting a <script> tag in a blog post content causing the javascript to be evaluated. Often, template engines have features for making it easier to design web user interfaces such as template inherritence and composition so you can share things like layouts, headers, and menus across pages.
- sametmax 9y ago+1. It can deal with non dev creating templates. It can compose templates. Manage caching. Embed logic. Debugging.
- dec0dedab0de 9y agosibling comments gave a much better explanation, but if you want to boil it down I think of it as python pretending to be PHP.
- nzjrs 9y agoI wonder if the new namespaces objects can be (ab)used to return state from macros.
- yoavm 9y agoI wish Python had more templating engines like Jade (now Pug), Slim & HAML. I can't go back to writing HTML anymore. I know about PyJade but it's (and all it's forks) seems always highly unmaintained.