# Unable to figure out arrays

**URL:** <https://forum.ansible.com/t/unable-to-figure-out-arrays/16481>\
**Category:** Ansible Project\
**Created:** [October 9, 2014, 11:36pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481 "2014-10-09T23:36:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [October 9, 2014, 11:36pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/1 "2014-10-09T23:36:25Z")

</div>

I would like to be able to put my users into a list and be able to select what user has access to each machine.

---

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [October 9, 2014, 11:56pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/2 "2014-10-09T23:56:01Z")

</div>

Please ignore the second mail: under bob

---

<div class="post-metadata">

**Author:** ![Michael\_Vermaes](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@Michael\_Vermaes](https://forum.ansible.com/u/Michael_Vermaes)\
**Post date:** [October 10, 2014, 6:20am UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/3 "2014-10-10T06:20:10Z")

</div>

Hi Michael, I think you want something like:

---

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [October 10, 2014, 6:59am UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/4 "2014-10-10T06:59:22Z")

</div>

Thanks for your response Michael. I've already read through that page  
a few times. It does not work for me because I need an array of users,  
and then I need to be able to select which user have access to each  
class of server. This method would give every user access to every  
machine. I need to be able to specify something like with items -  
users.alice - users.bob and not have carol included.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 10, 2014, 12:36pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/5 "2014-10-10T12:36:19Z")

</div>

for that just do :

vars:  
&nbsp;&nbsp;....  
&nbsp;&nbsp;&nbsp;&nbsp;allowed\_users\_host1: ['alice,'bob']  
....  
&nbsp;&nbsp;&nbsp;&nbsp;- name: Add user  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="Add user {{ item.key }} password {{ item.value.pass }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_dict: users  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: item.key in allowed\_users\_host1

---

<div class="post-metadata">

**Author:** ![adam2](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@adam2](https://forum.ansible.com/u/adam2)\
**Post date:** [October 10, 2014, 4:35pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/6 "2014-10-10T16:35:50Z")

</div>

- name: foo  
&nbsp;&nbsp;&nbsp;shell: echo "{{ users[item].name }}"  
&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- alice  
&nbsp;&nbsp;&nbsp;&nbsp;- bob

---

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [October 10, 2014, 6:51pm UTC](https://forum.ansible.com/t/unable-to-figure-out-arrays/16481/7 "2014-10-10T18:51:44Z")

</div>

Awesome! Thank you so much for your responses Michael, Brian, and  
Adam. Both solutions from Brian and Adam work, thank you! If any of  
you get to Los Angeles I owe you a drink!

This is working great:

&nbsp;&nbsp;- name: Users | create .gitconfig  
&nbsp;&nbsp;&nbsp;&nbsp;shell: git config --global user.name '{{ item.value.name }}'; git  
config --global user.email '{{ item.value.mail }}'  
&nbsp;&nbsp;&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;creates: /home/{{ item.key }}/.gitconfig  
&nbsp;&nbsp;&nbsp;&nbsp;sudo: yes  
&nbsp;&nbsp;&nbsp;&nbsp;sudo\_user: "{{ item.key }}"  
&nbsp;&nbsp;&nbsp;&nbsp;with\_dict: users  
&nbsp;&nbsp;&nbsp;&nbsp;when: item.key in allowed\_users\_dev  
&nbsp;&nbsp;&nbsp;&nbsp;tags: git

What I like about the with\_dict approach is I can do "when: item.key  
not in allowed\_users\_dev" with "user: name={{ item.key }}  
state=absent".
