---
- name: Ensure that the git group exists
  ansible.builtin.group:
    name: "{{ git_group }}"
    state: present

- name: add git user
  ansible.builtin.user:
    name: "{{ git_user }}"
    home: "{{ git_homedir }}"
    create_home: yes
    shell: "/bin/bash"
    groups: "{{ git_group }}"
    append: true
    state: present

#- name: add authorized_key to user
#  ansible.posix.authorized_key:
#    user: git
#    state: present
#    key: "{{ lookup('file', 'files/XXX.pub') }}"

- name: Add authorized_key for users
  ansible.posix.authorized_key:
    user: "{{ item.user }}"
    state: present
    key: "{{ lookup('file', 'files/' + item.key) }}"
  loop: "{{ users }}"

#- name: create repositories directory
#  ansible.builtin.file:
#    path: "{{ git_repos }}"
#    owner: "{{ git_user }}"
#    group: "{{ git_group }}"
#    state: directory
#    mode: u=rwx,g=rwx,o=r

