- name: Make the directories to hold jupyter config
  file:
    state: directory
    path: '{{ item }}'
  with_items:
     - '{{ jupyter_venv }}/etc/jupyter'
     - '{{ jupyter_venv }}/etc/jupyterhub'
     - '{{ jupyter_venv }}/etc/systemd'

- name: "Set 'nodejs_install: True' and 'nodejs_enabled: True'"
  set_fact:
    nodejs_install: True
    nodejs_enabled: True

- name: NODEJS - run 'nodejs' role (attempt to install & enable Node.js)
  include_role:
    name: nodejs

- name: FAIL (STOP THE INSTALL) IF 'nodejs_installed is undefined'
  fail:
    msg: "Jupyter install cannot proceed, as Node.js is not installed."
  when: nodejs_installed is undefined

- name: use npm to install configurable http proxy
  npm:
      name: configurable-http-proxy
      global: yes
      state: latest

- name: Use pip to install into a virtual environment
  pip:
    name:
       - pip
       - wheel
       - ipywidgets
       - jupyterhub
       - jupyterlab
       - jupyterhub_firstuseauthenticator
       - jupyterhub-systemdspawner
    virtualenv: "{{ jupyter_venv }}"    # /opt/iiab/jupyter
    virtualenv_site_packages: no
    virtualenv_command: /usr/bin/virtualenv
    virtualenv_python: python3
    extra_args: "--no-cache-dir"
  when: internet_available
    
- name: Install the config file for jupyterhub
  template:
      src: jupyterhub_config.py
      dest: '{{ jupyter_venv }}/etc/jupyterhub/'

- name: Use systemd to start jupyterhub
  template:
      src: jupyter.service
      dest: /etc/systemd/system/
