ansible-jinjia2模板

1. 含义
是基于python的模板引擎,包含变量和表达式两部分,这两者在模板求值的时候会被替换为值;
模板中还有标签,控制模板的逻辑
2. 基础语法
- 模板的表达式都包含在分隔符"{{ }}"内的
- 控制语句都包含在"{% %}"内的
- 另外模板也支持注释,都是包含在分隔符"{# #}"中,支持块注释
//调用变量
{{varname}}
//计算
{{2+3}}}
//判断
{{1 in [1,2,3]}}
3. 过滤器也就是管道'|'
变量可以通过过滤器修改;过滤器与变量通过|来分割,并且也可以用()来传递可选参数;
多个过滤器可以链式调用,前一个过滤器的输出会被作为后一个过滤器的输入
When nothing seems to help, I go look at a stonecutter hammering away at his rock, perhaps a hundred times without as much as a crack showing in it. Yet at the hundred and first blow it will split in two, and I know it was not that blow that did it, but all that had gone before. -- Jacob Riis
原文地址:https://www.cnblogs.com/xhwy-1234/p/12163593.html