From 447b609c88521973484e248b91f776d485da3f41 Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Wed, 10 Nov 2021 12:51:00 +0100
Subject: [PATCH] Install helm as snap

Closes: #995
---
 ansible/group_vars/all/stackspin.yml       |  8 ---
 ansible/roles/pre-configure/tasks/main.yml | 62 ++++++++--------------
 2 files changed, 23 insertions(+), 47 deletions(-)

diff --git a/ansible/group_vars/all/stackspin.yml b/ansible/group_vars/all/stackspin.yml
index 8ee195e8e..655724a49 100644
--- a/ansible/group_vars/all/stackspin.yml
+++ b/ansible/group_vars/all/stackspin.yml
@@ -20,14 +20,6 @@ k3s:
   # https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
   server_args: "--disable traefik --disable local-storage --disable servicelb --kube-apiserver-arg=event-ttl=48h0m0s --tls-san {{ ip_address }}"
 
-helm:
-  # helm snap 2.15.0 and 2.15.1 broke for us
-  # (https://open.greenhost.net/stackspin/stackspin/issues/338), so we
-  # use a pinned version for now.
-  # We use the official helm install script for now which has no checksum.
-  # https://github.com/helm/helm/releases
-  version: 'v3.2.1'
-
 krew:
   # https://github.com/kubernetes-sigs/krew/releases
   version: 'v0.3.4'
diff --git a/ansible/roles/pre-configure/tasks/main.yml b/ansible/roles/pre-configure/tasks/main.yml
index 530f814fe..c8e72460c 100644
--- a/ansible/roles/pre-configure/tasks/main.yml
+++ b/ansible/roles/pre-configure/tasks/main.yml
@@ -50,6 +50,8 @@
 # Once the debian issue is solved and Greenhost has patched the kernel, these
 # three workaround commands can be removed.
 - name: Workaround debian bug 1/3
+  tags:
+    - snap
   shell: "journalctl -k | awk '/input: Xen Virtual Keyboard/ {print $11}'"
   args:
     # Only run this if kubectl snap has not been installed yet
@@ -59,6 +61,8 @@
   changed_when: false
 
 - name: Workaround debian bug 2/3
+  tags:
+    - snap
   # kubectl needs to get installed as "classic" snap
   mount:
     opts: bind
@@ -68,57 +72,37 @@
     state: mounted
   when: kbd_device.stdout != "" and kbd_device.stdout != "skipped, since /snap/bin/kubectl exists"
 
-- name: Install kubectl snap
-  # kubectl needs to get installed as "classic" snap
-  command: snap install --classic kubectl
+- name: Install kubectl and helm snap
+  tags:
+    - snap
+  # kubectl and helm both need to get installed as "classic" snap
+  command: "snap install --classic {{ item }}"
   args:
-    creates: /snap/bin/kubectl
+    creates: "/snap/bin/{{ item }}"
+  with_items:
+    - helm
+    - kubectl
 
 - name: Workaround debian bug 3/3
+  tags:
+    - snap
   # kubectl needs to get installed as "classic" snap
   mount:
     path: /sys/{{ kbd_device.stdout }}/uevent
     state: unmounted
   when: kbd_device.stdout != "" and kbd_device.stdout != "skipped, since /snap/bin/kubectl exists"
 
-- name: Create kubectl symlink to /usr/local/bin
+- name: Create kubectl and helm symlinks to /usr/local/bin
+  tags:
+    - snap
   file:
     state: link
-    src: /snap/bin/kubectl
-    dest: /usr/local/bin/kubectl
-
-- name: Get current helm version
-  tags:
-    - helm
-  # {{ '{{' }} escapes the curly braces needed by the `--template` argument
-  shell: "helm version --template \"{{ '{{' }} .Version {{ '}}' }}\""
-  failed_when: false
-  register: helm_version
-  changed_when: false
-
-- name: Show current helm version
-  tags:
-    - helm
-    - debug
-  debug:
-    msg: 'Current helm version is: {{ helm_version.stdout }}'
-
-- name: Download helm install script
-  tags:
-    - helm
-  get_url:
-    url: https://raw.githubusercontent.com/helm/helm/master/scripts/get
-    dest: /usr/local/bin/get-helm
-    force: yes
-    mode: '0755'
-  become: true
-  when: helm_version.stdout != helm.version
-
-- name: Install helm
-  tags:
+    src: "/snap/bin/{{ item }}"
+    dest: "/usr/local/bin/{{ item }}"
+    force: true
+  with_items:
     - helm
-  command: /usr/local/bin/get-helm --version {{ helm.version }}
-  when: helm_version.stdout != helm.version
+    - kubectl
 
 - name: Configure firewall
   import_tasks: firewall.yml
-- 
GitLab