mirror of
https://github.com/roles-ansible/ansible_collection_users.git
synced 2024-08-16 10:29:50 +02:00
L3D
f1eb517563
Addoption to create groups CLOSE https://github.com/roles-ansible/ansible_collection_users/issues/26
59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
---
|
|
- name: Create Groups for Users
|
|
become: true
|
|
ansible.builtin.group:
|
|
name: "{{ user.name }}"
|
|
state: 'present'
|
|
loop: "{{ _l3d_users__merged_users }}"
|
|
loop_control:
|
|
label: "user={{ user.name }}"
|
|
loop_var: user
|
|
when: user.state | default ('present') == 'present'
|
|
|
|
- name: Optionally create additional Groups
|
|
become: true
|
|
ansible.builtin.group:
|
|
name: "{{ item }}"
|
|
state: 'present'
|
|
with_items: "{{ l3d_users__additional_groups }}"
|
|
|
|
- name: Create Accounts for Users
|
|
become: true
|
|
ansible.builtin.user:
|
|
name: "{{ user.name }}"
|
|
group: "{{ user.name }}"
|
|
groups: "{{ user.groups | default() }}"
|
|
state: 'present'
|
|
create_home: "{{ user.create_home | default(true) }}"
|
|
home: "{{ user.home | default('/home/' + user.name) }}"
|
|
comment: "{{ user.comment | default(user.name) }}"
|
|
shell: "{{ user.shell | default('/bin/bash') }}"
|
|
password: "{{ user.password | default() }}"
|
|
loop: "{{ _l3d_users__merged_users }}"
|
|
loop_control:
|
|
label: "user={{ user.name }}"
|
|
loop_var: user
|
|
when: user.state | default ('present') == 'present'
|
|
|
|
- name: Remove Accounts for Users
|
|
become: true
|
|
ansible.builtin.user:
|
|
name: "{{ user.name }}"
|
|
state: 'absent'
|
|
remove: "{{ user.remove | default(false) }}"
|
|
loop: "{{ _l3d_users__merged_users }}"
|
|
loop_control:
|
|
label: "user={{ user.name }}"
|
|
loop_var: user
|
|
when: user.state | default ('present') == 'absent' and user.remove | default(false) | bool
|
|
|
|
- name: Remove Groups for Users
|
|
become: true
|
|
ansible.builtin.group:
|
|
name: "{{ user.name }}"
|
|
state: 'absent'
|
|
loop: "{{ _l3d_users__merged_users }}"
|
|
loop_control:
|
|
label: "user={{ user.name }}"
|
|
loop_var: user
|
|
when: user.state | default ('present') == 'absent' and user.remove | default(false) | bool
|