--- - 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: Optionally create additional Groups become: true ansible.builtin.group: name: "{{ item }}" state: 'present' with_items: "{{ l3d_users__additional_groups }}" - 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) }}" home: "{{ user.home | default('/home/' + user.name) }}" comment: "{{ user.comment | default(user.name) }}" 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