title: Iterating over an array within an array in Ansible
body: <p>I wish to create entries in /etc/security.limits.conf<br>
  The data structure will look something like this:</p>
  
  <pre><code>limits:
    - root:
      - "soft nproc unlimited"
      - "hard nfile unlimited"
    - ec2-user:
      - "soft nproc 4096"
  </code></pre>
  
  <p>Producing lines in /etc/security.conf like so:</p>
  
  <blockquote>
    <p>root soft nproc unlimited<br>
    root hard nfile unlimited<br>
    ec2-user soft nproc 4096  </p>
  </blockquote>
  
  <p>The data definition produces a dictionary of arrays.  The outer dictionary is keyed by user, each of which has its own array of lines to add.</p>
  
  <p>I expect the code to look something like this pseudocode:  </p>
  
  <pre><code>  for user in $limits   
       for line in $user  
          lineinfile $line ...  
       end  
    end  
  </code></pre>
  
  <p>I just can't see how to do this with Ansible.</p>
  
  <p>I've been doing debugging with a debug task so I can see what the  {{ item }} contains - like so:</p>
  
  <pre><code> - name: limits | Set limits in /etc/security/limits.conf
       debug:
         msg: item is {{ item }}
       loop: "{{ limits }} "
  </code></pre>
  
  <p>But how do I get at the individual elements of the array?  There could be up to 16 possible array elements - one for each tunable parameter.</p>
  
  <p>I've found this impossible to google - all the results refer to Ansible docs, which I've read thoroughly - is not always with comprehension.</p>
  
  <p>Any pointers much appreciated, and apologies if I'm missing something obvious!</p>