我有一些简单的(ascii)支柱数据,看起来像这样(有些简化):
host:
name:
user: 'jeff'
pass: 'sekret'
在盐(sls)文件中,我这样调用一个Jinja模板:
{% set the_name = pillar.get('host')['name'] %}
/dev/null/myfile:
file.managed:
source: myfile_template
...
-defaults:
stuff: {{ the_name }
在myfile_template
中,我指的是{{ stuff.user }}
。有人告诉我stuff
没有属性'user'。如果我尝试{{ stuff["user"] }}
或{{ stuff['user'] }}
,也是如此。
在盐2018.3.2中,此代码有效。 在salt 2019.2.0中,此代码不起作用,并且出现上述错误。
只需将{{ stuff }}
插入文件(使用salt 2019.2.0),则该值为
{u"u'user'": u"u'jeff'", u"u'pass'": u"u'sekret'" }
我很确定双unicode指示器是我的问题的征兆,但是我有点茫然了。 有什么建议可能是我做错了什么或更改了什么?
答案 0 :(得分:1)
正如您所说的,它在2018.3中而不是在2019.2中起作用,因此您应该查看https://docs.saltstack.com/en/latest/topics/releases/2019.2.0.html上可用的2019.2版本说明。
它在https://docs.saltstack.com/en/latest/topics/releases/2019.2.0.html#non-backward-compatible-change-to-yaml-renderer上明确提到了“向YAML渲染器的非向后兼容更改”。
如果打算仅使用salt 2019.2,则应将stuff: {{ the_name}}
更改为stuff: {{ the_name|tojson }}
,如果打算也与旧版本兼容,则应将stuff: {{ the_name|json }}
更改为