title: Chef templates and how to do a for loop in ruby
body: <p>I am very new to ruby and chef.  I am trying to create entries in an nginx.conf file based on the number of cores.</p>
  
  <pre><code>for i in &lt;%= node["cpu"]["total"]%&gt;
  upstream frontends {
          server 127.0.0.1:805x;
      }
  
  end
  </code></pre>
  
  <p>So..if 4 cores the file will look like this:</p>
  
  <pre><code>upstream frontends {
              server 127.0.0.1:8051;
              server 127.0.0.1:8052;
              server 127.0.0.1:8053;
              server 127.0.0.1:8054;
          }
  </code></pre>