ansible.builtin.user multiple groups with jinjia2

67 views
Skip to first unread message

Tony Wong

unread,
Jul 1, 2022, 1:32:23 PM7/1/22
to Ansible Project
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


aide...@gmail.com

unread,
Jul 1, 2022, 1:40:45 PM7/1/22
to ansible...@googlegroups.com
You can use groups_vars for any group in your inventory

Enviado desde mi iPhone

El 01-07-2022, a la(s) 13:32, Tony Wong <tdub...@gmail.com> escribió:

any idea how I can create a user and then put it into multiple groups with jinja2?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5bb32ddb-57be-4133-aa03-22a1ff06a542n%40googlegroups.com.

Walter Rowe

unread,
Jul 5, 2022, 2:43:37 PM7/5/22
to Ansible Project
The groups parameter is a simple list of strings. It is clearly documented in the module description.

groups: [ "{{ username }}", "{{ groupname }}" ]

Reply all
Reply to author
Forward
0 new messages