1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_collection_users.git synced 2024-08-16 10:29:50 +02:00
ansible_collection_users/roles/user/tasks/users.yml

53 lines
1.6 KiB
YAML
Raw Normal View History

---
- name: Create Groups for Users
become: true
ansible.builtin.group:
2024-02-18 15:44:57 +01:00
name: "{{ user.name }}"
state: 'present'
2024-02-14 21:25:00 +01:00
loop: "{{ _l3d_users__merged_users }}"
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'
- 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() }}"
state: 'present'
2024-02-18 15:44:57 +01:00
create_home: "{{ user.create_home | default(true) }}"
home: "{{ user.home | default('/home/' + user.name) }}"
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 }}"
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'
- name: Remove Accounts for Users
become: true
ansible.builtin.user:
2024-02-18 15:44:57 +01:00
name: "{{ user.name }}"
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 }}"
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
- name: Remove Groups for Users
become: true
ansible.builtin.group:
2024-02-18 15:44:57 +01:00
name: "{{ user.name }}"
state: 'absent'
2024-02-14 21:25:00 +01:00
loop: "{{ _l3d_users__merged_users }}"
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