Add support for custom user groups

main^2
Moritz 'e1mo' Fromm 4 years ago
parent 7bfaee6e72
commit c59bb754e3
Signed by: e1mo
GPG Key ID: 1D5D79A439E787F1

@ -1,4 +1,6 @@
--- ---
user_groups: []
users: users:
- { name: 'user', state: 'present', public_key: '' } - { name: 'user', state: 'present', public_key: '' }
- { name: 'nouser', state: 'absent', public_key: '' } - { name: 'nouser', state: 'absent', public_key: '' }

@ -7,6 +7,12 @@
with_items: with_items:
- "{{ users }}" - "{{ users }}"
- name: Ensure all groups are present or absent
group:
name: '{{ item.name | default(item) }}'
state: '{{ item.state | default("present") }}'
with_items: '{{ user_groups }}'
- name: get bash's path - name: get bash's path
command: which bash command: which bash
register: bash_path register: bash_path
@ -14,10 +20,15 @@
changed_when: false changed_when: false
- name: create user - name: create user
user: state=present user:
name="{{ item.username if item.username is defined else item.name }}" state: present
groups="{{ "sudo,adm" if item.sudo is defined and item.sudo }}" append=yes name: "{{ item.username if item.username is defined else item.name }}"
shell={{ item.shell | default(bash_path.stdout) }} groups:
- "{{ item.groups | default([]) | join(',')}}"
- "{{ 'sudo,adm' if item.sudo is defined and item.sudo }}"
append: true
shell: '{{ item.shell | default(bash_path.stdout) }}'
home: "{{ item.home | default('/home/' + (item.username | default(item.name))) }}"
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state != 'absent' when: item.state != 'absent'

Loading…
Cancel
Save