How to put a if statement inside a loop within a chef template file?

590 Views Asked by At

This works great without the if statement but not sure what the best way to use the if is ?

 <% node['some-node']['datasource'].each do |dbname,values| -%>
              <%= if (dbname.to_s != 'ReferenceData') -%>
    <Resource auth="${JDBC.<%= dbname %>.auth}" driverClassName="${JDBC.<%= dbname %>.driverClassName}" initialSize="${JDBC.<%= dbname %>.initialSize}" factory="${JDBC.<%= dbname %>.factory}" testWhileIdle="${JDBC.<%= dbname %>.testWhileIdle}" timeBetweenEvictionRunsMillis="${JDBC.<%= dbname %>.timeBetweenEvictionRunsMillis}" minEvictableIdleTimeMillis="${JDBC.<%= dbname %>.minEvictableIdleTimeMillis}" maxActive="${JDBC.<%= dbname %>.maxActive}" minIdle="${JDBC.<%= dbname %>.minIdle}" name="${JDBC.<%= dbname %>.name}" password="${JDBC.<%= dbname %>.password}" testOnBorrow="${JDBC.<%= dbname %>.testOnBorrow}" type="${JDBC.<%= dbname %>.type}" url="${JDBC.<%= dbname %>.url}" username="${JDBC.<%= dbname %>.userName}" validationInterval="${JDBC.<%= dbname %>.validationInterval}" validationQuery="${JDBC.<%= dbname %>.validationQuery}" connectionProperties="${JDBC.<%= dbname %>.connectionProperties}"/>
               <% end %>
     <% end %>
1

There are 1 best solutions below

0
On

You want to use <% instead of <%=. The = version is for an expression that you want to capture the output from, the one without is for Ruby code which you want for structure but the value of it doesn't matter. You might also want to use <%- which turns on whitespace trimming.