oopen-server/roles/common/tasks/samba-remove-user.yml
2024-06-09 01:30:38 +02:00

60 lines
1.3 KiB
YAML

---
# ---
# - Remove unwanted users
# ---
- name: "(samba-remove-user.yml) Check if samba user exists for removable system user"
shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep -q '{{ item.name }}'
register: samba_remove_system_users_present
changed_when: "samba_remove_system_users_present.rc == 0"
failed_when: "samba_remove_system_users_present.rc > 1"
with_items:
- "{{ remove_samba_users }}"
loop_control:
label: '{{ item.name }}'
tags:
- system-user
- samba-user
- name: (samba-remove-user.yml) Remove (old) system users from samba
shell: >
smbpasswd -s -x {{ item.item.name }}
with_items:
- "{{ samba_remove_system_users_present.results }}"
loop_control:
label: '{{ item.item.name }}'
when:
- item.changed
tags:
- system-user
- samba-user
- name: (samba-remove-user.yml) Remove users from system
user:
name: '{{ item.name }}'
state: absent
with_items:
- "{{ remove_samba_users }}"
loop_control:
label: '{{ item.name }}'
tags:
- system-user
- samba-user
- name: (samba-remove-user.yml) Remove home directory from deleted users
file:
path: "{{ base_home | default('/home', true) }}/{{ item.name }}"
state: absent
with_items:
- "{{ remove_samba_users }}"
loop_control:
label: '{{ item.name }}'
tags:
- system-user
- samba-user