---

- name: Ensure socioboard group is created
  ansible.builtin.group:
    name: "{{ socioboard_user_groupname }}"
    gid: "{{ socioboard_user_gid }}"
    state: present
  tags: setup-all

- name: Ensure socioboard user is created
  ansible.builtin.user:
    name: "{{ socioboard_user_username }}"
    shell: /bin/bash
    groups: "{{ socioboard_user_groupname }}"
  tags: setup-all

- name: Ensure folders are created
  ansible.builtin.file:
    path: "{{ socioboard_base_data_path }}"
    state: directory
    owner: "{{ socioboard_user_username }}"
    group: "{{ socioboard_user_groupname }}"
  tags: 
    - setup
    - setup-all

- name: Ensure we have a local copy of source code and configs
  ansible.builtin.git:
    repo: "{{ socioboard_git_repo }}"
    dest: "{{ socioboard_base_data_path }}"
  ignore_errors: true
  tags: 
    - setup
    - setup-all
    - update

- name: Ensure Docker .env is installed
  ansible.builtin.copy:
    src: files/docker.env
    dest: "{{ socioboard_base_data_path }}/docker/.env"
    owner: "{{ socioboard_user_username }}"
    group: "{{ socioboard_user_groupname }}"
  tags: 
    - setup
    - setup-all
    - update

- name: Create mongo init script
  ansible.builtin.script:
    cmd: files/mongo-init.sh
    chdir: "{{ socioboard_base_data_path }}"
  tags: 
    - setup
    - setup-all
    - update
