From ade5f7c8ac6a8b2d7b76a680020a2dcf26698c25 Mon Sep 17 00:00:00 2001
From: Georg Krause <mail@georg-krause.net>
Date: Fri, 16 Jun 2023 15:45:51 +0200
Subject: [PATCH] feat: Install Ansible in venv

---
 install.sh | 13 +++++++------
 upgrade.sh |  3 ++-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/install.sh b/install.sh
index 0a895e7..209d7ef 100755
--- a/install.sh
+++ b/install.sh
@@ -20,7 +20,7 @@ min_python_version_major="3"
 min_python_version_minor="5"
 base_path="/srv/funkwhale"
 ansible_conf_path="$base_path/ansible"
-ansible_bin_path="$HOME/.local/bin"
+ansible_venv_path="$HOME/.local/ansible"
 ansible_funkwhale_role_version="${ANSIBLE_FUNKWHALE_ROLE_VERSION-master}"
 ansible_funkwhale_role_path="${ANSIBLE_FUNKWHALE_ROLE_PATH-}"
 funkwhale_systemd_after=""
@@ -216,9 +216,10 @@ do_install() {
 
 init_ansible() {
     echo "[2/$total_steps] Installing ansible dependencies..."
-    install_packages  curl git python3-pip python3-apt python3-psycopg2 sudo locales locales-all
+    install_packages  curl git python3-pip python3-venv python3-apt python3-psycopg2 sudo locales locales-all
     echo "[2/$total_steps] Installing Ansible..."
-    pip3 install --user ansible=="$ansible_version"
+    python3 -m venv $ansible_venv_path
+    $ansible_venv_path/bin/pip3 install ansible=="$ansible_version"
 
     echo "[2/$total_steps] Creating ansible configuration files in $ansible_conf_path..."
     mkdir -p "$ansible_conf_path"
@@ -287,7 +288,7 @@ EOF
 #!/bin/sh
 # reapply playbook with existing parameter
 # Useful if you changed some variables in playbook.yml
-exec $ansible_bin_path/ansible-playbook  -i $ansible_conf_path/inventory.ini $ansible_conf_path/playbook.yml -u root $ansible_flags
+exec $ansible_venv_path/bin/ansible-playbook  -i $ansible_conf_path/inventory.ini $ansible_conf_path/playbook.yml -u root $ansible_flags
 EOF
     chmod +x ./reconfigure
     if [ "$funkwhale_redis_managed" = "false" ]; then
@@ -306,7 +307,7 @@ EOF
 EOF
     if [ "$ansible_funkwhale_role_path" = '' ]; then
         echo "[2/$total_steps] Downloading Funkwhale playbook dependencies"
-        $ansible_bin_path/ansible-galaxy install -r requirements.yml -f
+        $ansible_venv_path/bin/ansible-galaxy install -r requirements.yml -f
     else
         echo "[2/$total_steps] Skipping playbook dependencies, using local role instead"
     fi
@@ -314,7 +315,7 @@ EOF
 run_playbook() {
     cd "$ansible_conf_path"
     echo "[3/$total_steps] Installing Funkwhale using ansible playbook in $ansible_conf_path..."
-    playbook_command="$ansible_bin_path/ansible-playbook  -i $ansible_conf_path/inventory.ini $ansible_conf_path/playbook.yml -u root $ansible_flags"
+    playbook_command="$ansible_venv_path/bin/ansible-playbook  -i $ansible_conf_path/inventory.ini $ansible_conf_path/playbook.yml -u root $ansible_flags"
     if [ "$is_dry_run" = "true" ]; then
         playbook_command="$playbook_command --check"
         echo "[3/$total_steps] Skipping playbook because DRY_RUN=true"
diff --git a/upgrade.sh b/upgrade.sh
index c833a14..6747fe9 100755
--- a/upgrade.sh
+++ b/upgrade.sh
@@ -14,7 +14,8 @@ skip_confirm="${SKIP_CONFIRM-}"
 is_dry_run=${DRY_RUN-false}
 base_path="/srv/funkwhale"
 ansible_conf_path="$base_path/ansible"
-ansible_bin_path="$HOME/.local/bin"
+ansible_venv_path="$HOME/.local/ansible"
+ansible_bin_path="$ansible_venv_path/bin"
 ansible_funkwhale_role_version="${ANSIBLE_FUNKWHALE_ROLE_VERSION-master}"
 funkwhale_systemd_after=""
 total_steps="4"
-- 
GitLab