# playbook to create multiple users?

**URL:** <https://forum.ansible.com/t/playbook-to-create-multiple-users/12853>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [May 22, 2013, 11:45pm UTC](https://forum.ansible.com/t/playbook-to-create-multiple-users/12853 "2013-05-22T23:45:29Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [May 22, 2013, 11:45pm UTC](https://forum.ansible.com/t/playbook-to-create-multiple-users/12853/1 "2013-05-22T23:45:29Z")

</div>

This should work (was missing quote):

- name: create user(s)  
user: name=${item} shell=/bin/bash  
with\_file: “./user-list.txt”

adding same with\_file here and item for file name should do the rest:

- name: setup authorized key(s)  
action: authorized\_key user=xmxb077 key=‘$FILE(/home/xmxb077/Code/Ansible/user\_add/Users/${item}.pub)’

with\_file: “./user-list.txt”

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 23, 2013, 2:33am UTC](https://forum.ansible.com/t/playbook-to-create-multiple-users/12853/2 "2013-05-23T02:33:15Z")

</div>

I would totally simplify this rather than doing this as you say.

Define your list of users in something like a “users.yml” file

In the play:

vars\_files:

- vars/users.yml

That defines a variable users, which is a list of strings. Later this might be a hash of attributes about the user.

In the task:

with\_items: ${users}

Or in 1.2 syntax, simpler!

with\_items: users

The idea of loading them from a text file is fine, but loading them from a YAML file so they are data is better.

You may also move on to wanting to keep those definitions in a group\_vars/ file, so different hosts can get different lists of users, or even source that users list from external software later.

---

<div class="post-metadata">

**Author:** ![Michael\_Bogucki](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Michael\_Bogucki](https://forum.ansible.com/u/Michael_Bogucki)\
**Post date:** [May 23, 2013, 5:20pm UTC](https://forum.ansible.com/t/playbook-to-create-multiple-users/12853/3 "2013-05-23T17:20:51Z")

</div>

Hello Michael, Hello everyone,

First off thank you for the various suggestions. I ended up following Mr. DeHaan’s suggestions. After a few tries, it finally “clicked” and I can see what the flow was like amongst the various files.  
None-the-less, here’s a posting of what I’ve done to help any new-comers (like me 🙂 )  
As usual any suggestions are highly appreciated.

I’ll probably setup a git-repository and post it there for future reference.

_ **\*\*\* vars/users.yml \*\*\*** _

project\_root: /home/ubuntu/Code/Ansible/user\_add  
key\_files: /home/ubuntu/Code/Ansible/user\_add/Keys

users:

- xmxb070
- xlxr073
- xtxb007
- xmxk074
- xaxu077

group\_name:

- users

_ **\*\*\* user\_add.yml \*\*\*** _
