---
- name: Dependencies installed
  community.general.pkgng:
    name: py39-pip,py39-lxml,py39-gunicorn,bash,yarn-node18,git-tiny,npm-node18,rust
    state: latest

- name: Source folder exists
  file:
    path: /usr/local/src
    owner: root
    mode: 0755
    state: directory

- name: Wger source @ master
  git:
    repo: "https://github.com/wger-project/wger.git"
    dest: /usr/local/src/wger
    update: yes
    force: yes
  tags:
    - update

- name: Wger requirements up to date
  pip:
    requirements: /usr/local/src/wger/requirements.txt
    executable: pip

- name: sass installed
  shell:
    cmd: npm install -g sass
  tags:
    - update

- name: Wger UI built
  shell:
    cmd: yarn && yarn install
    chdir: /usr/local/src/wger/
  tags:
    - update

- name: Wger UI built
  shell:
    cmd: yarn build:css:sass
    chdir: /usr/local/src/wger/
  tags:
    - update

- name: Media directory exists
  file:
    path: /usr/local/www/wger/static/
    mode: 0755
    state: directory

- name: Static directory exists
  file:
    path: /usr/local/www/wger/media
    mode: 0755
    state: directory

- name: Wger conf file installed
  template:
    src: settings.py.j2
    dest: /usr/local/src/wger/settings.py
    owner: root
    mode: 0644

- name: Wger db migrated
  shell:
    cmd: python3.9 manage.py migrate
    chdir: /usr/local/src/wger/
  tags:
    - update

- name: Wger static files collected
  shell:
    cmd: python3.9 manage.py collectstatic --noinput
    chdir: /usr/local/src/wger/
  tags:
    - update

- name: Wger permissions updated
  shell:
    cmd: python3.9 manage.py loaddata groups.json categories.json
    chdir: /usr/local/src/wger/
  tags:
    - update

- name: Wger nginx file installed
  copy:
    src: nginx-location.conf
    dest: /usr/local/etc/nginx/locations/wger.conf
    mode: 0644
  notify: Nginx restarted

- name: Wger immortal file installed
  copy:
    src: immortal-wger.yml
    dest: /usr/local/etc/immortal/wger.yml
    mode: 0644
  notify: Immortal restarted
