Fix venv recreation after Python version change

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 <noreply@anthropic.com>
This commit is contained in:
Manu 2026-01-05 14:03:04 +00:00 committed by Manu
parent 4cb112712b
commit 91e793975f

View File

@ -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: