# Create users and groups using with\_files

**URL:** <https://forum.ansible.com/t/create-users-and-groups-using-with-files/24917>\
**Category:** Ansible Project\
**Created:** [July 7, 2017, 12:34am UTC](https://forum.ansible.com/t/create-users-and-groups-using-with-files/24917 "2017-07-07T00:34:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anfield](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@Anfield](https://forum.ansible.com/u/Anfield)\
**Post date:** [July 7, 2017, 12:34am UTC](https://forum.ansible.com/t/create-users-and-groups-using-with-files/24917/1 "2017-07-07T00:34:09Z")

</div>

Trying to create groups and then users using with files and its not working…How should the lists be represented in the groups vars file and the users vars file?

It doesnt like it just as text below…how am I supposed to list the values out? How do people normally create a few users and groups like this?

groups.yml

devops  
dbadmin  
business

users.yml

tom  
dave  
joe

Playbook  
— # Users and Groups

- hosts: localhost  
vars\_files:
- groups.yml
- users.yml  
tasks:
- name: Create groups  
group:  
name: “{{ item }}”  
state: present  
with\_file:
- groups.yml
- name: Create users  
user:  
name: “{{ item }}”  
state: present  
with\_file:
- users.yml

---

<div class="post-metadata">

**Author:** ![Daniel\_JD](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Daniel\_JD](https://forum.ansible.com/u/Daniel_JD)\
**Post date:** [July 7, 2017, 7:25pm UTC](https://forum.ansible.com/t/create-users-and-groups-using-with-files/24917/2 "2017-07-07T19:25:28Z")

</div>

Your files are not in YAML- Syntax. Ansible should give you an error if you start the playbook. You dont event need it at all.

Use with\_lines! Like this:

tasks:

- name: Create groups  
group:  
name: “{{ item }}”  
state: present  
with\_lines: cat groups.yml

- name: Create users  
user:  
name: “{{ item }}”  
state: present  
with\_lines: cat users.yml

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 7, 2017, 10:18pm UTC](https://forum.ansible.com/t/create-users-and-groups-using-with-files/24917/3 "2017-07-07T22:18:00Z")

</div>

The 'file' lookup does not deal with YAML so with\_files will just  
return an entry for the content of the file, 'lines' or split() should  
make it work.

Since you don't specify what "doesn't work" means ... I really cannot  
even guess at what the error is, always include the error you get when  
you are trying to have others help debugging.
