allow to installation via os package manager or pip

This commit is contained in:
Stefan Morgenthaler 2022-12-09 09:55:40 +01:00
parent e34f9311d8
commit 178316f8e7
12 changed files with 80 additions and 36 deletions

View File

@ -87,7 +87,8 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl
- `ssh_key_file`: Path to a private ssh key file (default is `.ssh/id_ed25519`). It generates a ed25519 key if the file doesn't exist yet.
- `borg_version`: Force a specific borg version to be installed
- `borgmatic_version`: Force a specific borgmatic version to be installed
- `borgmatic_install_method`: By default `pip` is used to install borgmatic. To install via your distributions package manager set this to `package-manager` and overwrite the `borg_packages` variable to contain your distributions package names required to install borgmatic. Note that many distributions ship outdated versions of borgbackup and borgmatic; use at your own risk.
- `borg_system_packages`: contains the names of distributions packages for `borg(backup)` and `borgmatic`, only used if `borgmatic_install_method` is set to `package-manager`.
## Contributing

View File

@ -35,7 +35,6 @@ borgmatic_cron_minute: "{{ 59 | random(seed=inventory_hostname) }}"
borgmatic_cron_checks_day: "{{ range(1, 28) | random(seed=inventory_hostname) }}"
borgmatic_cron_checks_hour: "{{ range(9, 24) | random(seed=inventory_hostname) }}"
borgmatic_cron_checks_minute: "{{ 59 | random(seed=inventory_hostname) }}"
borg_version: false
borgmatic_version: false
borgmatic_version: false
borgmatic_install_method: pip

34
tasks/install_pip.yml Normal file
View File

@ -0,0 +1,34 @@
---
- name: Create virtualenv for borg # noqa package-latest
pip:
name:
- pip
- setuptools
state: latest
virtualenv: /opt/borgmatic
virtualenv_command: "{{ python_bin }} -m venv"
- name: Install dependent Python Packages
pip:
name: "{{ borg_dependent_python_packages }}"
virtualenv: /opt/borgmatic
when: borg_dependent_python_packages is defined
- name: Install main Python Packages
pip:
name: "{{ item.name }}"
version: "{{ item.version | default(omit, true) }}"
virtualenv: /opt/borgmatic
when: borg_python_packages is defined
loop: "{{ borg_python_packages }}"
- name: Create borgmatic command in /usr/local/bin
copy:
content: |
#!/bin/bash
. /opt/borgmatic/bin/activate
borgmatic "$@"
dest: /usr/local/bin/borgmatic
owner: root
group: root
mode: "0755"

6
tasks/install_pkg.yml Normal file
View File

@ -0,0 +1,6 @@
---
- name: Install borgmatic and borg via distribution package manager
package:
name: "{{ item }}"
state: present
loop: "{{ borg_system_packages }}"

View File

@ -27,39 +27,15 @@
name: "{{ borg_packages }}"
state: present
- name: Create virtualenv for borg # noqa package-latest
pip:
name:
- pip
- setuptools
state: latest
virtualenv: /opt/borgmatic
virtualenv_command: "{{ python_bin }} -m venv"
- name: Install borgmatic via pip
ansible.builtin.include_tasks:
file: install_pip.yml
when: borgmatic_install_method == 'pip'
- name: Install dependent Python Packages
pip:
name: "{{ borg_dependent_python_packages }}"
virtualenv: /opt/borgmatic
when: borg_dependent_python_packages is defined
- name: Install main Python Packages
pip:
name: "{{ item.name }}"
version: "{{ item.version | default(omit, true) }}"
virtualenv: /opt/borgmatic
when: borg_python_packages is defined
loop: "{{ borg_python_packages }}"
- name: Create borgmatic command in /usr/local/bin
copy:
content: |
#!/bin/bash
. /opt/borgmatic/bin/activate
borgmatic "$@"
dest: /usr/local/bin/borgmatic
owner: root
group: root
mode: "0755"
- name: Install borgmatic via distribution package manager
ansible.builtin.include_tasks:
file: install_pkg.yml
when: borgmatic_install_method == 'package-manager'
- name: Ensure root has SSH key.
user:

View File

@ -7,5 +7,9 @@ borg_packages:
- python-pip
- python-setuptools
borg_system_packages:
- borg
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -13,5 +13,9 @@ borg_packages:
- openssh-client
- cron
borg_system_packages:
- borgbackup
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -13,5 +13,9 @@ borg_packages:
- openssh-clients
- cronie
borg_system_packages:
- borgbackup
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -4,5 +4,9 @@ borg_packages:
- openssh
- cronie
borg_system_packages:
- borg
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -13,5 +13,9 @@ borg_packages:
- openssh-clients
- cronie
borg_system_packages:
- borgbackup
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -13,5 +13,9 @@ borg_packages:
- openssh-clients
- cronie
borg_system_packages:
- borgbackup
- borgmatic
python_bin: python3
pip_bin: pip3

View File

@ -12,5 +12,9 @@ borg_packages:
- openssh-clients
- cronie
borg_system_packages:
- borgbackup
- borgmatic
python_bin: python3
pip_bin: pip3