title: Using jinja2 how can you do loop in a loop with the second loop an incrementing count to start and stop on var values?
body: <p>What is the easiest way using jinja2 (being called from ansible template function) to do a loop in a loop that will start with the first switch port and loop (count) to the last switch port and then continue to the next switch and do the same iteration?</p>
  <p>Any tips would be greating appreciated!</p>
  <p><strong>Sample variables:</strong></p>
  <pre><code>switches:
    - name: &quot;switch1&quot;
      first_port: &quot;1&quot;
      last_port: &quot;52&quot;
    - name: &quot;switch2&quot;
      first_port: &quot;1&quot;
      last_port: &quot;48&quot;
    - name: &quot;switch3&quot;
      first_port: &quot;1&quot;
      last_port: &quot;24&quot;
  </code></pre>
  <p><strong>Desired J2 template output:</strong></p>
  <pre><code>switch1:
    port:1
    port:2
    ...
    port:52
  
  switch2:
    port:1
    port:2
    ...
    port:48
  
  switch3:
    port:1
    port:2
    ...
    port:24
  
  </code></pre>