mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2026-02-14 13:51:23 +01:00
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:
parent
51e099e553
commit
1f4dc7c4c5
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user