From 1f4dc7c4c5ace71ef80dcbc04228f9ff98291eef Mon Sep 17 00:00:00 2001 From: Manu Date: Mon, 5 Jan 2026 14:03:04 +0000 Subject: [PATCH] Fix venv recreation after Python version change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After an OS upgrade, the Python version may change but the existing virtualenv at /opt/borgmatic still references the old Python binary. This causes ModuleNotFoundError when trying to run borgmatic. This fix adds checks before venv creation to: 1. Get the system's current Python version 2. Check the Python version in the existing venv (if any) 3. Remove the venv if versions don't match, allowing it to be recreated Fixes #113 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- tasks/noauto_install_pip.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tasks/noauto_install_pip.yml b/tasks/noauto_install_pip.yml index 770cf09..c9360f4 100644 --- a/tasks/noauto_install_pip.yml +++ b/tasks/noauto_install_pip.yml @@ -12,6 +12,25 @@ name: "{{ borg_pip_packages }}" state: present + - name: Get system Python version + ansible.builtin.command: "{{ python_bin }} --version" + register: borg_system_python_version + changed_when: false + + - name: Check Python version in existing borgmatic venv + ansible.builtin.command: "{{ borg_venv_path }}/bin/python --version" + register: borg_venv_python_version + failed_when: false + changed_when: false + + - name: Remove borgmatic venv if Python version doesn't match + ansible.builtin.file: + path: "{{ borg_venv_path }}" + state: absent + when: + - borg_venv_python_version.rc == 0 + - borg_venv_python_version.stdout != borg_system_python_version.stdout + - name: Create virtualenv for borg # noqa package-latest ansible.builtin.pip: name: