mirror of
https://github.com/roles-ansible/ansible_collection_users.git
synced 2024-08-16 10:29:50 +02:00
51 lines
1.5 KiB
YAML
51 lines
1.5 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: 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) }}"
|
|
comment: "User created by ansible"
|
|
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
|