Add new user and add to existing group

28 views
Skip to first unread message

Zeljko Dokman

unread,
Mar 19, 2018, 4:59:56 AM3/19/18
to Ansible Project
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 

Kai Stian Olstad

unread,
Mar 19, 2018, 8:15:48 AM3/19/18
to ansible...@googlegroups.com
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

Zeljko Dokman

unread,
Mar 19, 2018, 8:40:53 AM3/19/18
to Ansible Project

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
Reply all
Reply to author
Forward
0 new messages