# Add new user and add to existing group

**URL:** <https://forum.ansible.com/t/add-new-user-and-add-to-existing-group/27036>\
**Category:** Ansible Project\
**Created:** [March 19, 2018, 8:59am UTC](https://forum.ansible.com/t/add-new-user-and-add-to-existing-group/27036 "2018-03-19T08:59:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zeljko\_Dokman](https://avatars.discourse-cdn.com/v4/letter/z/f04885/32.png) [@Zeljko\_Dokman](https://forum.ansible.com/u/Zeljko_Dokman)\
**Post date:** [March 19, 2018, 8:59am UTC](https://forum.ansible.com/t/add-new-user-and-add-to-existing-group/27036/1 "2018-03-19T08:59:56Z")

</div>

Hi,

Can some one help me with my playbook for adding new user and adding that user to existing groups…

Playbook…

`

- hosts: “{{ target }}”  
become: yes  
become\_user: root  
become\_method: sudo  
gather\_facts: no

tasks:

- name: User add “{{ user }}”  
user: name=“{{ user }}” comment=“{{ comment }}” uid=“{{ uid }}” groups=“{{ groups }}”  
notify:
- Chage added user

handlers:

- name: Chage added user  
shell: chage -M 99999 “{{ user }}”

`

My command…

`

ansible-playbook user\_add\_and\_to\_group.yaml -K -e “target=egcp-tst-rde.mbu.local user=test1 comment=testuser uid=9990 groups=sysadm”

`

I am getting this error…  
“msg”: “argument groups is of type \<type ‘dict’\> and we were unable to convert to list: \<type ‘dict’\> cannot be converted to a list”

If I use the play book without groups parameter playbook is successful if I manually define groups directly in the playbook its successful but it fails if I use it with variables and I do not understand why

Regards

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 19, 2018, 12:15pm UTC](https://forum.ansible.com/t/add-new-user-and-add-to-existing-group/27036/2 "2018-03-19T12:15:24Z")

</div>

groups is a reserved variable name in Ansible, groups contain all the groups in the inventory.  
[http://docs.ansible.com/ansible/latest/playbooks\_variables.html#magic-variables-and-how-to-access-information-about-other-hosts](http://docs.ansible.com/ansible/latest/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts)

---

<div class="post-metadata">

**Author:** ![Zeljko\_Dokman](https://avatars.discourse-cdn.com/v4/letter/z/f04885/32.png) [@Zeljko\_Dokman](https://forum.ansible.com/u/Zeljko_Dokman)\
**Post date:** [March 19, 2018, 12:40pm UTC](https://forum.ansible.com/t/add-new-user-and-add-to-existing-group/27036/3 "2018-03-19T12:40:53Z")

</div>

> groups is a reserved variable name in Ansible, groups contain all the  
> groups in the inventory.  
> [http://docs.ansible.com/ansible/latest/playbooks\_variables.html#magic-variables-and-how-to-access-information-about-other-hosts](http://docs.ansible.com/ansible/latest/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts)
> 
> –  
> Kai Stian Olstad

So simple solution but it did not cross my mind,  
Thank you for your help.

Best regards
