---
- name: Remove users
  become: true
  ansible.builtin.user:
    name: "{{ item }}"
    state: absent
    remove: true
  register: remove_users
  with_items:
    - "{{ delete_users }}"
  failed_when: >
    remove_users is not success and
    not ("not removing" in remove_users.msg or
    "not found" in remove_users.msg)
  tags:
    - users

- name: Stat user /home directories
  ansible.builtin.find:
    paths: /home
    file_type: directory
  register: home_directories
  tags:
    - users
    - CIS-UBUNTU2004-6.2.6
    - M1022

- name: Set user /home directories permission
  become: true
  ansible.builtin.file:
    mode: "0750"
    path: "{{ item.path }}"
  with_items: "{{ home_directories.files }}"
  loop_control:
    label: "{{ item.path }}"
  tags:
    - users
    - CIS-UBUNTU2004-6.2.6
    - M1022
