From f1fb94db5157cea09c3cffea806b73356b09e391 Mon Sep 17 00:00:00 2001
From: Daniel M <daniel.q.mueller@stud.h-da.de>
Date: Tue, 9 Nov 2021 09:22:20 +0100
Subject: [PATCH] Optimize apt usage

- Moved `python3-pip` and `python3-venv` into local.yml as base dependencies
- Update apt cache while installing base dependencies in local.yml
- Remove redundant installs and cache updates from roles
---
 local.yml                               | 18 ++++++++++--------
 roles/jupyter-lab/tasks/main.yml        | 11 -----------
 roles/ml-python-packages/tasks/main.yml | 15 +--------------
 3 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/local.yml b/local.yml
index 466be3f..4a61bae 100644
--- a/local.yml
+++ b/local.yml
@@ -18,14 +18,16 @@
     #     update_cache: true
     #     force_apt_get: true
 
-    # - name: Install pip3
-    #   become: true
-    #   apt:
-    #     update_cache: true
-    #     name:
-    #       - python3-pip
-    #       - libffi-dev # This is needed for jupyter on aarch64 to compile its C backend
-    #     state: present
+    - name: Update apt cache & install base requirements
+      become: true
+      apt:
+        update_cache: true
+        state: present
+        name:
+          - python3-pip
+          - python3-venv
+    #     - libffi-dev # This is needed for jupyter on aarch64 to compile its C backend
+    
 
   roles:
     - jupyter-lab
diff --git a/roles/jupyter-lab/tasks/main.yml b/roles/jupyter-lab/tasks/main.yml
index f5b9df2..f7ded5a 100644
--- a/roles/jupyter-lab/tasks/main.yml
+++ b/roles/jupyter-lab/tasks/main.yml
@@ -8,17 +8,6 @@
     owner: "{{ target_user }}"
     group: "{{ target_user }}"
 
-# This should be optimized so that only one check / install is needed
-# Still we should make sure that pip3 is actually installed before trying to use it
-- name: Install dependecies
-  become: true
-  apt:
-    name:
-      - python3-pip
-      - python3-venv
-    state: present
-    update_cache: true
-
 - name: Install jupyter-lab
   pip:
     virtualenv_command: /usr/bin/python3 -m venv
diff --git a/roles/ml-python-packages/tasks/main.yml b/roles/ml-python-packages/tasks/main.yml
index ee1c3cf..168e1ae 100644
--- a/roles/ml-python-packages/tasks/main.yml
+++ b/roles/ml-python-packages/tasks/main.yml
@@ -1,16 +1,12 @@
 ---
 # roles/ml-python-packages
 
-# This should be optimized so that only one check / install for pip3 is needed
-# Still we should make sure that pip3 is actually installed before trying to use it
 - name: Install dependecies
   become: true
   apt:
     name:
-      - python3-pip
       - libatlas-base-dev
     state: present
-    update_cache: true
 
 - name: Copy requirements.txt to remote fs
   copy:
@@ -22,13 +18,4 @@
     virtualenv_command: /usr/bin/python3 -m venv
     requirements: /tmp/ml-requirements.txt
     virtualenv: "/home/{{ target_user }}/.ml-venv"
-    # name:
-      # - numpy
-      # - sklearn
-      # - matplotlib
-      # - pandas
-      # - Pillow
-      # - torch
-      # - torchvision
-      # - fastai
-    # state: present
+
-- 
GitLab