# iterations within iterations OH NOES (1.9)

**URL:** <https://forum.ansible.com/t/iterations-within-iterations-oh-noes-1-9/21723>\
**Category:** Ansible Project\
**Created:** [June 9, 2016, 2:05pm UTC](https://forum.ansible.com/t/iterations-within-iterations-oh-noes-1-9/21723 "2016-06-09T14:05:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [June 9, 2016, 2:05pm UTC](https://forum.ansible.com/t/iterations-within-iterations-oh-noes-1-9/21723/1 "2016-06-09T14:05:43Z")

</div>

Hi all

(tldr: i want to run a task for each hash in a list . can i iterate twice?)

I want to define a 'global' user list like this  
(e.g in roles/accounts/defaults/main.yml):

all\_the\_users:  
&nbsp;&nbsp;- support:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Jimmy The Exploder  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: jim  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Bobby Tables  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: bob  
&nbsp;&nbsp;- devs  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Typhoid Mary  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: mary  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Count Zero  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: bobby

and then be able to give some groups SSH access and some sudo access  
by defining 2 lists in each of our environments:

ssh\_groups:  
&nbsp;&nbsp;&nbsp;&nbsp;- devs  
&nbsp;&nbsp;&nbsp;&nbsp;- support

sudo\_groups:  
&nbsp;&nbsp;- support

I'm trying to get my head around iteration here - really I need to  
'for each group in {{ ssh\_groups }} , create users via with\_dict or similar.

I've read [http://docs.ansible.com/ansible/playbooks\_loops.html](http://docs.ansible.com/ansible/playbooks_loops.html) but  
can't get my head  
around how/if i can iterate twice if you see what i mean.

is this possible?

If there's a different 'shape' to the data that would allow this,  
please let me know.
