Python 带盐堆的Jinja2回路
使用for循环时,我的jinja2模板遇到问题。我想我只是为了得到正确的语法而变得愚蠢Python 带盐堆的Jinja2回路,python,templates,jinja2,salt,Python,Templates,Jinja2,Salt,使用for循环时,我的jinja2模板遇到问题。我想我只是为了得到正确的语法而变得愚蠢 {% for options in salt['pillar.get']('nexus.file.nexus.vmoptions') %} //trying to access a yaml list (posted below)` {% for addjavavariables in options %} //trying to get the lists out of the options {{ n
{% for options in salt['pillar.get']('nexus.file.nexus.vmoptions') %}
//trying to access a yaml list (posted below)`
{% for addjavavariables in options %}
//trying to get the lists out of the options
{{ nexus.file.nexus.vmoptions.addjavavariables[0] }}
//trying to write every single line from my list
{{ addjavavariables }}:
- {{ addjavavariables }}
{% endfor %}
{% endfor %}
YAML看起来像这样
最终文件应该如下所示
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.s'tartLocalConsole=false
-Djava.util.prefs.userRoot=/home/nexus/.java
我的问题是,我没有把任何东西放到文件里。它也根本不会进入循环。有谁能给我一个提示,我如何将列表中的所有项目以一个起始破折号放入文件中?的路径分隔符是:
,而不是
,因此您应该使用salt['pillar.get']('nexus:file:nexus:vmoptions')
但是,您也可以简单地使用
支柱['nexus']['file']['nexus']['vmoptions']
奇怪的是,你有2个用于循环,但只有1个列表需要迭代。nexus:file:nexus:vmoptions
dict中是否有其他键
为了获得所需的结果,我会选择:
{% for addjavavariable in salt['pillar.get']('nexus:file:nexus:vmoptions:addjavavariables', []) %}
-{{ addjavavariable }}
{% endfor %}
非常感谢你!它工作得很好。我想我必须迭代列表中的每一项才能得到该项。我不知道我可以使用addjavavariables
自动获取每一项。我想我总是需要像addjavavariables[index].value这样的东西。我认为你的答案是对的。
{% for addjavavariable in salt['pillar.get']('nexus:file:nexus:vmoptions:addjavavariables', []) %}
-{{ addjavavariable }}
{% endfor %}