2024-02-14 03:16:24 +01:00
|
|
|
---
|
|
|
|
- name: Create Groups for Users
|
|
|
|
become: true
|
|
|
|
ansible.builtin.group:
|
2024-02-18 15:44:57 +01:00
|
|
|
name: "{{ user.name }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
state: 'present'
|
2024-02-14 21:25:00 +01:00
|
|
|
loop: "{{ _l3d_users__merged_users }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
loop_control:
|
2024-02-18 15:44:57 +01:00
|
|
|
label: "user={{ user.name }}"
|
|
|
|
loop_var: user
|
2024-03-22 16:40:22 +01:00
|
|
|
when: user.state | default ('present') == 'present'
|
2024-02-14 03:16:24 +01:00
|
|
|
|
|
|
|
- name: Create Accounts for Users
|
|
|
|
become: true
|
|
|
|
ansible.builtin.user:
|
2024-02-18 15:44:57 +01:00
|
|
|
name: "{{ user.name }}"
|
|
|
|
group: "{{ user.name }}"
|
2024-02-23 19:13:13 +01:00
|
|
|
groups: "{{ user.groups | default() }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
state: 'present'
|
2024-02-18 15:44:57 +01:00
|
|
|
create_home: "{{ user.create_home | default(true) }}"
|
2024-03-21 19:49:09 +01:00
|
|
|
home: "{{ user.home | default('/home/' + user.name) }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
comment: "User created by ansible"
|
2024-02-18 15:44:57 +01:00
|
|
|
shell: "{{ user.shell | default('/bin/bash') }}"
|
|
|
|
password: "{{ user.password | default() }}"
|
2024-02-14 21:25:00 +01:00
|
|
|
loop: "{{ _l3d_users__merged_users }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
loop_control:
|
2024-02-18 15:44:57 +01:00
|
|
|
label: "user={{ user.name }}"
|
|
|
|
loop_var: user
|
2024-03-22 16:40:22 +01:00
|
|
|
when: user.state | default ('present') == 'present'
|
2024-02-14 03:16:24 +01:00
|
|
|
|
|
|
|
- name: Remove Accounts for Users
|
|
|
|
become: true
|
|
|
|
ansible.builtin.user:
|
2024-02-18 15:44:57 +01:00
|
|
|
name: "{{ user.name }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
state: 'absent'
|
2024-02-18 15:44:57 +01:00
|
|
|
remove: "{{ user.remove | default(false) }}"
|
2024-02-14 21:25:00 +01:00
|
|
|
loop: "{{ _l3d_users__merged_users }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
loop_control:
|
2024-02-18 15:44:57 +01:00
|
|
|
label: "user={{ user.name }}"
|
|
|
|
loop_var: user
|
|
|
|
when: user.state | default ('present') == 'absent' and user.remove | default(false) | bool
|
2024-02-14 03:16:24 +01:00
|
|
|
|
|
|
|
- name: Remove Groups for Users
|
|
|
|
become: true
|
|
|
|
ansible.builtin.group:
|
2024-02-18 15:44:57 +01:00
|
|
|
name: "{{ user.name }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
state: 'absent'
|
2024-02-14 21:25:00 +01:00
|
|
|
loop: "{{ _l3d_users__merged_users }}"
|
2024-02-14 03:16:24 +01:00
|
|
|
loop_control:
|
2024-02-18 15:44:57 +01:00
|
|
|
label: "user={{ user.name }}"
|
|
|
|
loop_var: user
|
|
|
|
when: user.state | default ('present') == 'absent' and user.remove | default(false) | bool
|