问题
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.
回答1:
<%
node['db2']['instance_username'].each do |device|
%>
/home/<%= device %>/sqllib/lib64
<% end %>
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.
来源:https://stackoverflow.com/questions/27600349/how-to-run-for-each-loop-in-template-chef