在属性和附加数据上使用keys.join()
我有两组属性需要在 Chef 中组合,
Set 1
cert1.sec1.offdtr.dev
cert2.sec1.offdtr.dev
Set 2
cert3.sec2.ondrt.dev,
cert4.sec2.ondrt.dev
我可以在每个数据集上使用keys.join(',') 将它们连接在一起。
<% node['code']['block'][sec1].keys.join(','),node['code']['block'][sec2].keys.join(',') %>
但我需要第二次行动;将 */ 附加到每个值。输出应该类似于:
*/cert1.sec1.offdtr.dev,*/cert2.sec1.offdtr.dev,*/cert3.sec2.ondrt.dev,*/cert4.sec1.ondrt.dev
我如何在厨师模板中执行此操作?
I have two set's of attributes i need to combine in Chef
Set 1
cert1.sec1.offdtr.dev
cert2.sec1.offdtr.dev
Set 2
cert3.sec2.ondrt.dev,
cert4.sec2.ondrt.dev
I can use keys.join(',') on each data set to concat them together.
<% node['code']['block'][sec1].keys.join(','),node['code']['block'][sec2].keys.join(',') %>
But i need a second action ; append */ to each value. Output should be something like :
*/cert1.sec1.offdtr.dev,*/cert2.sec1.offdtr.dev,*/cert3.sec2.ondrt.dev,*/cert4.sec1.ondrt.dev
How can i do this in a chef template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,在厨师模板中,我们需要使用
&lt;%=
(请注意=
标志)以获取呈现属性/变量的值。与此同时,我们可以使用,*/
加入密钥。因此,如果您在模板(
.erb
)文件中放置下面的内容:渲染时它将产生预期结果:
在食谱中,我们使用
#{..}
for变量的插值。例如,当在其他地方使用mycerts
变量时,它将产生完全相同的结果。Firstly, in Chef template, we need to use
<%=
(note the=
sign) to get the value of attributes/variables rendered. Along with this, we can use,*/
to join the keys.So if you put something like below in a template (
.erb
) file:It will produce the expected result when rendered:
In a recipe we use
#{..}
for interpolation of variables. For e.g. when themycerts
variable defined below is used elsewhere, it will result in exactly the same result.