<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello,<br>
<br>
The previous email was sent to the wrong mailing-list, but as it is
quite relevant here I will translate it.<br>
<br>
The context is that we are adding Jinja2 templating support to
ncf/Rudder (<a class="moz-txt-link-freetext" href="http://www.rudder-project.org/redmine/issues/9022">http://www.rudder-project.org/redmine/issues/9022</a>). <br>
<br>
The currently supported templating format, Mustache, can be used is
two different ways in CFEngine:<br>
<ul>
<li>Using the current context (which is used in ncf). In this
case, the classes/variables are accessible using</li>
<ul>
<li><tt>{{vars.my_bundle.my_variable}}</tt> for variables<br>
</li>
<li><tt>{{#classes.my_class}}</tt> for classes<br>
</li>
</ul>
<li>Using a given json string as data, using the data directly
like <tt>{{my_variable}}</tt> (and without the concept of class).<br>
</li>
</ul>
We need to decide how we want to map this in jinja2 templates. We
can use the same data structure, with classes and vars, which should
allow using the same<br>
variable names as in Rudder mustache templates. However, this is a
bit unusual for jinja2 templates, and could bother people using
existing templates.<br>
<br>
What do you think about this?<br>
<br>
Concerning implementation, we can do it directly in CFEngine/ncf,
using a python script to render the template, and a standard file
edition. This would only require adding a new function to CFEngine
to be able to output the data needed for templating (becase
datastate()'s result is currently too big).<br>
<br>
Another option is to integrate it into CFEngine by:<br>
<ul>
<li>Adding a new template type</li>
<li>Generating the needed data<br>
</li>
<li>Making this template type use a python module, which would
take the template and the json data from stdin, and would output
the expanded string.</li>
</ul>
<p>Does anyone see possible issues with these options, or another
way to do it?</p>
<p>Alexis<br>
</p>
On 09/19/2016 02:58 PM, Alexis Mousset wrote:<br>
<blockquote
cite="mid:2c00dbdc-54d5-ff28-3881-8fa9b38d6ffc@normation.com"
type="cite">
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<p>Bonjour@Rudder,</p>
<p>La version de base du templating jinja2 dans Rudder (fonction
datastate() qui écrit dans un fichier + script python qui prend
en argument un template et le json de datastate et l'écrit dans
la destination), j'ai un poc fonctionnel. Il reste du code ncf à
écrire pour faire le templating et le script python à reprendre
(pour l'instant j'utilise jinja2-cli mais on peut faire plus
simple, et en plus gérer le success/repaired/error), et
éventuellement élaguer un peu le json produit.<br>
</p>
<p>Quelques questions concernant le format de templating jinja :</p>
<ul>
<li>Est-ce qu'on veut coller à ce qui se fait en mustache en
CFEngine ? C'est à dire utiliser dans les template des <tt>{%if
<font color="#ff0000">classes</font>.maclasse %}</tt> et <tt>{{
<font color="#ff0000">vars</font>.bundle.variable }}</tt> au
lieu de <tt>{%if maclasse}</tt> et <tt>{{ bundle.variable }}</tt>,
avec la possibilité de passer un json "verbatim" qui sera
interprété tel quel ? Cela demande de modifier des templates
existants, mais c'est de toutes façons probablement le cas si
on veut utiliser le contexte et pas un json en source de
données. En plus ça collera au templating mustache et passera
peut-être mieux upstream, même si ça peut être un peu
déroutant pour un habitué au templating (hors CFEngine).<br>
</li>
</ul>
<p>De plus, une version propre pourrait consister en :<br>
</p>
<ul>
<li>un vrai type de template en CFEngine, au même titre que
mustache</li>
<li>un script python dans un module au sens CFEngine<br>
</li>
<li>un passage de données au module sans utiliser un fichier
mais directement sur stdin/stdout<br>
</li>
<li>un module qui ne ferait pas l'édition lui même, mais
seulement le templating, laissant l'édition, avec tous les
problèmes de droits/backup, etc. à CFEngine<br>
</li>
</ul>
<p>Qu'est ce qui est prioritaire/indispensable de livrer pour la
prochaine mineure ? Est-ce qu'on commence par une version
"dégradée" en améliorant par la suite ? (en faisant attention à
bien penser la signature des generic methods).<br>
</p>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<style type="text/css">
<!--
a.redlink:link { color: #1782E6; }
a.redlink:visited { color: #1782E6; }
.sig { font-family: 'Century Gothic', CenturyGothic, AppleGothic, sans-serif; font-size: small; }
.sigsmall { font-family: 'Century Gothic', CenturyGothic, AppleGothic, sans-serif; font-size: x-small; }
-->
</style>
<table cellpadding="0" cellspacing="2" border="0" width="380">
<tbody>
<!--
<a href="https://www.normation.com/fr/"><img alt="Logo Normation" src="file:///home/amousset/Images/signature/logo-newsite.gif" /></a>
--> <tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2"><b><img alt="Logo Normation"
src="cid:part1.B3459235.295F01BC@normation.com"
align="left" height="50" hspace="10" width="50"> <span
class="sig">Alexis MOUSSET</span></b><br>
<span class="sig"><i>System Engineer</i></span><br>
<span class="sig"><a moz-do-not-send="true"
class="redlink" href="http://www.normation.com">Normation</a></span>
</td>
</tr>
<tr>
<td colspan="2">
<hr></td>
</tr>
<tr>
<td colspan="2"><span class="sigsmall"><b>87, Rue de
Turbigo, 75003 Paris, France</b></span></td>
</tr>
<tr>
<td><span class="sigsmall">Phone:</span></td>
<td><span class="sigsmall">+33 (0)1 84 17 77 93</span></td>
</tr>
<!--
<tr>
<td><span class="sigsmall">Mobile:</span></td>
<td><span class="sigsmall">+33 (0)6 00 00 00 00</span></td>
</tr>
--> <tr>
<td colspan="2">
<hr> </td>
</tr>
</tbody>
</table>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
rudder-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rudder-dev@lists.rudder-project.org">rudder-dev@lists.rudder-project.org</a>
<a class="moz-txt-link-freetext" href="http://www.rudder-project.org/mailman/listinfo/rudder-dev">http://www.rudder-project.org/mailman/listinfo/rudder-dev</a>
</pre>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<style type="text/css">
<!--
a.redlink:link { color: #1782E6; }
a.redlink:visited { color: #1782E6; }
.sig { font-family: 'Century Gothic', CenturyGothic, AppleGothic, sans-serif; font-size: small; }
.sigsmall { font-family: 'Century Gothic', CenturyGothic, AppleGothic, sans-serif; font-size: x-small; }
--></style></div>
</body>
</html>