From 0c31b39427ae705867dbd7933923921c33e7051f Mon Sep 17 00:00:00 2001
From: Daniel M <daniel.q.mueller@stud.h-da.de>
Date: Mon, 8 Nov 2021 16:05:14 +0100
Subject: [PATCH] Check python version + service opt-out

- Python version check is set to allow 3.7.x - 3.9.x
- The version check can be disabled with the `ignore_python_version` variable
- The systemd service can be opt-out with `jupyter_service` variable
---
 local.yml                        | 7 +++++++
 roles/jupyter-lab/tasks/main.yml | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/local.yml b/local.yml
index 7e7673c..466be3f 100644
--- a/local.yml
+++ b/local.yml
@@ -2,8 +2,15 @@
 - hosts: localhost
   vars:
     target_user: pi
+    jupyter_service: true
+    ignore_python_version: false 
 
   pre_tasks:
+    - name: Check python version
+      fail:
+        msg: Python version is not supported. Set ignore_python_version to true to ignore this.
+      when: (not ignore_python_version) and not (ansible_python_version is version('3.7.0', '>=') and ansible_python_version is version('3.10.0', '<'))
+
     # - name: Upgrade packages
     #   become: true
     #   apt:
diff --git a/roles/jupyter-lab/tasks/main.yml b/roles/jupyter-lab/tasks/main.yml
index 695242f..f5b9df2 100644
--- a/roles/jupyter-lab/tasks/main.yml
+++ b/roles/jupyter-lab/tasks/main.yml
@@ -32,7 +32,8 @@
     src: files/jupyter.service
     dest: /etc/systemd/system/jupyter.service
     mode: '0644'
-  
+  when: jupyter_service
+
 - name: Start Jupyter-Lab service
   become: true
   systemd:
@@ -40,4 +41,5 @@
     state: started
     enabled: true
     daemon_reload: true
+  when: jupyter_service
 
-- 
GitLab