# ansible.builtin.user multiple groups with jinjia2

**URL:** <https://forum.ansible.com/t/ansible-builtin-user-multiple-groups-with-jinjia2/36791>\
**Category:** Ansible Project\
**Created:** [July 1, 2022, 5:32pm UTC](https://forum.ansible.com/t/ansible-builtin-user-multiple-groups-with-jinjia2/36791 "2022-07-01T17:32:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony\_Wong](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tony\_Wong](https://forum.ansible.com/u/Tony_Wong)\
**Post date:** [July 1, 2022, 5:32pm UTC](https://forum.ansible.com/t/ansible-builtin-user-multiple-groups-with-jinjia2/36791/1 "2022-07-01T17:32:23Z")

</div>

any idea how I can create a user and then put it into multiple groups with jinja2?

- name: create user sam  
ansible.builtin.user:  
name: ‘{{ username }}’  
shell: ‘{{ shell }}’  
generate\_ssh\_key: yes  
create\_home: yes  
groups: “‘{{ username }}’,‘{{ groupname }}’”  
append: yes  
ssh\_key\_file: .ssh/id\_rsa  
become: true

where {{ username }} is sam  
{{ groupname }} is docker

---

<div class="post-metadata">

**Author:** ![aidewuado](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@aidewuado](https://forum.ansible.com/u/aidewuado)\
**Post date:** [July 1, 2022, 5:40pm UTC](https://forum.ansible.com/t/ansible-builtin-user-multiple-groups-with-jinjia2/36791/2 "2022-07-01T17:40:30Z")

</div>

You can use groups\_vars for any group in your inventory

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [July 5, 2022, 6:43pm UTC](https://forum.ansible.com/t/ansible-builtin-user-multiple-groups-with-jinjia2/36791/3 "2022-07-05T18:43:37Z")

</div>

The groups parameter is a simple list of strings. It is clearly documented in the module description.

**groups: [“{{ username }}”, “{{ groupname }}”]**
