# Thoughts on role for creating multiple users

**URL:** <https://forum.ansible.com/t/thoughts-on-role-for-creating-multiple-users/22450>\
**Category:** Ansible Project\
**Created:** [September 1, 2016, 1:10pm UTC](https://forum.ansible.com/t/thoughts-on-role-for-creating-multiple-users/22450 "2016-09-01T13:10:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![appeltabak](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@appeltabak](https://forum.ansible.com/u/appeltabak)\
**Post date:** [September 1, 2016, 1:10pm UTC](https://forum.ansible.com/t/thoughts-on-role-for-creating-multiple-users/22450/1 "2016-09-01T13:10:29Z")

</div>

Hi,

Currently, I’m transforming my user role from creating one user to creating multiple users. In many examples I’ve seen this is done by adding with\_items to every tasks related to the creation of the user (create user, add authorized key, etc). This would result in executing every tasks for every listed user before moving to the next tasks (right?) But what I want is that the whole task file is run from top to bottom, for every listed user.

I’ve tried this approach: [https://gist.github.com/Appeltabak/7f20f9f6e4fed80202cc2dd5d0044b5f](https://gist.github.com/Appeltabak/7f20f9f6e4fed80202cc2dd5d0044b5f)  
Unfortunately, this gives an undefined variable error when the outer\_users is used in subsequent tasks.

_TL;DR How can I run a task file with_ _with\_items_ ?

Thanks

---

<div class="post-metadata">

**Author:** ![Iain\_M\_Conochie](https://avatars.discourse-cdn.com/v4/letter/i/3ab097/32.png) [@Iain\_M\_Conochie](https://forum.ansible.com/u/Iain_M_Conochie)\
**Post date:** [September 2, 2016, 9:58am UTC](https://forum.ansible.com/t/thoughts-on-role-for-creating-multiple-users/22450/2 "2016-09-02T09:58:26Z")

</div>

OK - so you define your user vars like this in vars/users.yml:

users:  
&nbsp;&nbsp;&nbsp;- name: User of apples  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user: apple  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uid: 500  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;home: /home/apple  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /bin/bash  
&nbsp;&nbsp;&nbsp;- name: Orange Guy  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user: orange  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uid: 501  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;home: /home/orange  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: /bin/bash

Then a basic playbook would be:
