Add new user and add to existing group

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

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

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


Kai Stian Olstad

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

Best regards