From 2fc665dcad3db3057e39eecc4530607750cb438d Mon Sep 17 00:00:00 2001
From: Georg Krause <mail@georg-krause.net>
Date: Tue, 22 Aug 2023 13:58:32 +0200
Subject: [PATCH] fix: Do not try to install certbot if already available

---
 tasks/nginx.yml | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tasks/nginx.yml b/tasks/nginx.yml
index d1182df..86fcb46 100644
--- a/tasks/nginx.yml
+++ b/tasks/nginx.yml
@@ -15,30 +15,35 @@
 
 # from https://gist.github.com/mattiaslundberg/ba214a35060d3c8603e9b1ec8627d349
 
+- name: Check if certbot is already installed
+  stat:
+    path: "/usr/bin/certbot"
+  register: "certbot_installed"
+
 - name: Install snapd
-  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled
+  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled and not certbot_installed.stat.exists
   become: true
   package:
     name: snapd
     state: present
 
 - name: Prepare snapd for certbot installation
-  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled
+  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled and not certbot_installed.stat.exists
   become: true
   command: snap install core
 
 - name: Refresh core snap before installing certbot
-  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled
+  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled and not certbot_installed.stat.exists
   become: true
   command: snap refresh core
 
 - name: Install certbot snap
-  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled
+  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled and not certbot_installed.stat.exists
   become: true
   command: snap install --classic certbot
 
 - name: Link certbot snap installation
-  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled
+  when: funkwhale_nginx_managed and funkwhale_letsencrypt_enabled and not certbot_installed.stat.exists
   become: true
   file:
     src: /snap/bin/certbot
-- 
GitLab