---
# roles/jupyter-lab

- name: Notebooks dir
  file:
    path: "/home/{{ target_user }}/notebooks"
    state: directory
    owner: "{{ target_user }}"
    group: "{{ target_user }}"

- name: Install jupyter-lab
  become: true
  become_user: "{{ target_user }}"
  pip:
    virtualenv_command: /usr/bin/python3 -m venv
    virtualenv: "/home/{{ target_user }}/.ml-venv"
    name: jupyterlab==3.2.4
    state: present

- name: Install systemd service
  become: true
  template:
    src: files/jupyter.service
    dest: /etc/systemd/system/jupyter.service
    mode: '0644'
  when: jupyter_service

- name: Make systemd service autostart
  become: true
  file:
    src: /etc/systemd/system/jupyter.service
    dest: /etc/systemd/system/multi-user.target.wants/jupyter.service
    state: link
  when: jupyter_service and jupyter_autostart

- name: Start Jupyter-Lab service
  become: true
  systemd:
    name: jupyter
    state: started
    daemon_reload: true
  when: jupyter_service and jupyter_start

- name: Create Desktop dir
  become: true
  become_user: "{{ target_user }}"
  file:
    path: "/home/{{ target_user }}/Desktop"
    state: directory

- name: Copy desktop entry to desktop
  become: true
  become_user: "{{ target_user }}"
  copy:
    src: files/jupyter.desktop
    dest: "/home/{{ target_user }}/Desktop/jupyter.desktop"