From eac3b86097396d78a2776e3d1f2c7b167dd7f793 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Apr 2021 19:21:35 +0000 Subject: [PATCH] Lint for readability & maintainability --- roles/jupyterhub/defaults/main.yml | 10 ++- roles/jupyterhub/tasks/enable-or-disable.yml | 17 ++--- roles/jupyterhub/tasks/install.yml | 76 +++++++++++-------- roles/jupyterhub/tasks/main.yml | 4 +- .../templates/jupyterhub-nginx.conf | 3 +- vars/default_vars.yml | 1 + 6 files changed, 63 insertions(+), 48 deletions(-) diff --git a/roles/jupyterhub/defaults/main.yml b/roles/jupyterhub/defaults/main.yml index a859f9946..60a53efa4 100644 --- a/roles/jupyterhub/defaults/main.yml +++ b/roles/jupyterhub/defaults/main.yml @@ -1,2 +1,8 @@ -jupyterhub_venv: /opt/iiab/jupyterhub -jupyterhub_port: 8000 +# jupyterhub_install: False +# jupyterhub_enabled: False + +# jupyterhub_venv: /opt/iiab/jupyterhub +# jupyterhub_port: 8000 + +# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml +# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing! diff --git a/roles/jupyterhub/tasks/enable-or-disable.yml b/roles/jupyterhub/tasks/enable-or-disable.yml index aacd9a35d..1c8a720cc 100644 --- a/roles/jupyterhub/tasks/enable-or-disable.yml +++ b/roles/jupyterhub/tasks/enable-or-disable.yml @@ -3,33 +3,28 @@ daemon_reload: yes -# enable or disable -- name: Enable & Restart jupyterhub +- name: Enable & Restart jupyterhub.service systemd: - name: "{{ item }}" + name: jupyterhub enabled: yes state: restarted - with_items: - - jupyterhub.service when: jupyterhub_enabled -- name: Disable jupyterhub +- name: Disable jupyterhub.service systemd: - name: "{{ item }}" + name: jupyterhub enabled: no state: stopped - with_items: - - jupyterhub when: not jupyterhub_enabled -- name: Put the nginx config file in place +- name: 'Install from template: {{ nginx_conf_dir }}/jupyterhub-nginx.conf' template: src: jupyterhub-nginx.conf dest: "{{ nginx_conf_dir }}/" when: jupyterhub_enabled -- name: Disable jupyterhub +- name: Disable {{ nginx_conf_dir }}/jupyterhub-nginx.conf file: path: "{{ nginx_conf_dir }}/jupyterhub-nginx.conf" state: absent diff --git a/roles/jupyterhub/tasks/install.yml b/roles/jupyterhub/tasks/install.yml index baae04456..26ea0cb01 100644 --- a/roles/jupyterhub/tasks/install.yml +++ b/roles/jupyterhub/tasks/install.yml @@ -1,12 +1,3 @@ -- name: Make the directories to hold jupyter config - file: - state: directory - path: '{{ item }}' - with_items: - - '{{ jupyterhub_venv }}/etc/jupyter' - - '{{ jupyterhub_venv }}/etc/jupyterhub' - - '{{ jupyterhub_venv }}/etc/systemd' - - name: "Set 'nodejs_install: True' and 'nodejs_enabled: True'" set_fact: nodejs_install: True @@ -18,38 +9,61 @@ - name: FAIL (STOP THE INSTALL) IF 'nodejs_installed is undefined' fail: - msg: "Jupyter install cannot proceed, as Node.js is not installed." + msg: "JupyterHub 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 +- name: Make the directories to hold JupyterHub config + file: + state: directory + path: '{{ item }}' + with_items: + - '{{ jupyterhub_venv }}/etc/jupyter' + - '{{ jupyterhub_venv }}/etc/jupyterhub' + - '{{ jupyterhub_venv }}/etc/systemd' + +- 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: {{ jupyterhub_venv }}' pip: name: - - pip - - wheel - - ipywidgets - - jupyterhub - - jupyterlab - - jupyterhub_firstuseauthenticator - - jupyterhub-systemdspawner + - pip + - wheel + - ipywidgets + - jupyterhub + - jupyterlab + - jupyterhub_firstuseauthenticator + - jupyterhub-systemdspawner virtualenv: "{{ jupyterhub_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: '{{ jupyterhub_venv }}/etc/jupyterhub/' -- name: Use systemd to start jupyterhub +- name: 'Install from template: {{ jupyterhub_venv }}/etc/jupyterhub/jupyterhub_config.py' template: - src: jupyterhub.service - dest: /etc/systemd/system/ + src: jupyterhub_config.py + dest: '{{ jupyterhub_venv }}/etc/jupyterhub/' + +- name: 'Install from template: /etc/systemd/system/jupyterhub.service' + template: + src: jupyterhub.service + dest: /etc/systemd/system/ + + +# RECORD JupyterHub AS INSTALLED + +- name: "Set 'jupyterhub_installed: True'" + set_fact: + jupyterhub_installed: True + +- name: "Add 'jupyterhub_installed: True' to {{ iiab_state_file }}" + lineinfile: + path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml + regexp: '^jupyterhub_installed' + line: 'jupyterhub_installed: True' diff --git a/roles/jupyterhub/tasks/main.yml b/roles/jupyterhub/tasks/main.yml index 56807c2ea..86460681e 100644 --- a/roles/jupyterhub/tasks/main.yml +++ b/roles/jupyterhub/tasks/main.yml @@ -38,7 +38,7 @@ value: JupyterHub - option: description value: '"High Schools may want to consider JupyterHub to integrate coding with dynamic interactive graphing — A New Way to Think About Programming — allowing students to integrate science experiment results and program output within their notebook/document/blog."' - - option: install + - option: jupyterhub_install value: "{{ jupyterhub_install }}" - - option: enabled + - option: jupyterhub_enabled value: "{{ jupyterhub_enabled }}" diff --git a/roles/jupyterhub/templates/jupyterhub-nginx.conf b/roles/jupyterhub/templates/jupyterhub-nginx.conf index 32c999261..0c97d4caf 100644 --- a/roles/jupyterhub/templates/jupyterhub-nginx.conf +++ b/roles/jupyterhub/templates/jupyterhub-nginx.conf @@ -1,11 +1,10 @@ -location /jupyterhub { +location /jupyterhub { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; - # websocket headers proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; diff --git a/vars/default_vars.yml b/vars/default_vars.yml index 87dfd0444..ac70d7509 100644 --- a/vars/default_vars.yml +++ b/vars/default_vars.yml @@ -383,6 +383,7 @@ gitea_port: 61734 # JupyterHub programming environment with student Notebooks jupyterhub_install: False jupyterhub_enabled: False +jupyterhub_venv: /opt/iiab/jupyterhub jupyterhub_port: 8000 # Lokole (email for rural communities) from https://ascoderu.ca