如何在模板厨师中为每个循环运行 [英] How to Run for each loop in template chef

查看:47
本文介绍了如何在模板厨师中为每个循环运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组形式的属性,我想在Chef模板中对其进行迭代?

I have a attribute in the form of array, and i want to iterate over it in Chef template ?

<% node['db2']['instance_username'].each do |device| -%> 
  <%= "/home/#{device}/sqllib/lib64" %>
<% end -%>

我正在这样做,但它给出了错误。

I'm doing like this but it is giving error.

推荐答案

<% 
node['db2']['instance_username'].each do |device| 
%> 
  /home/<%= device %>/sqllib/lib64
<% end %>

我会改成这样。如果您遇到错误,请尝试将结尾连字符找出来,它们是Rails的构造,我不确定它们是否能很好地交叉,但是如果您发布了所遇到的错误,这会很有帮助。实例用户名很可能不是数组。

I'd rewrite it like this instead. If you are having an error try taking out the end hyphens out they are a rails construct and I'm not sure if they cross over well but it would help a lot if you posted the error you are having. Most likely instance username is not an array.

这篇关于如何在模板厨师中为每个循环运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆