Chef Ruby loop over attributes in an .erb template file

前端 未结 2 1873
执笔经年
执笔经年 2021-02-09 20:12

So this might be a little confusing but bear with me. In short I want to loop over all attributes with a certain key value and then insert them into a template if the values ar

2条回答
  •  旧巷少年郎
    2021-02-09 20:41

    What you probably meant was:

    <% node['elasticsearch']['default'].each do |key, value| -%>
        <% unless value.empty? -%>
            <%= key %>=<%= value %>
        <% end %>
    <% end %>
    

    When iterating over a Hash, you go over its key-value pairs. So for the first iteration, key will be 'ES_USER', and value will be '' (which is not nil...).

    Next you check that the value is not blank?, and print out the key=value line.

提交回复
热议问题