Skip to content

Commit 981d4f9

Browse files
moregeekm3nu
andauthored
Allow to installation via OS package manager or pip (borgbase#106)
* allow to installation via os package manager or pip * Run a second time to install via package manager * Check for EPEL if distro package requested. * Split dep lists to avoid installing build deps when using distro pkg Co-authored-by: Stefan Morgenthaler <[email protected]> Co-authored-by: Manu <[email protected]>
1 parent e34f931 commit 981d4f9

18 files changed

+140
-69
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ $ git clone https://github.com/borgbase/ansible-role-borgbackup.git roles/ansibl
8787
- `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.
8888
- `borg_version`: Force a specific borg version to be installed
8989
- `borgmatic_version`: Force a specific borgmatic version to be installed
90-
90+
- `borg_install_method`: By default `pip` is used to install borgmatic. To install via your distributions package manager set this to `package` and (if needed) overwrite the `borg_distro_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.
91+
- `borg_distro_packages`: contains the names of distributions packages for `borg(backup)` and `borgmatic`, only used if `borg_install_method` is set to `package`.
9192

9293
## Contributing
9394

defaults/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ borgmatic_cron_minute: "{{ 59 | random(seed=inventory_hostname) }}"
3535
borgmatic_cron_checks_day: "{{ range(1, 28) | random(seed=inventory_hostname) }}"
3636
borgmatic_cron_checks_hour: "{{ range(9, 24) | random(seed=inventory_hostname) }}"
3737
borgmatic_cron_checks_minute: "{{ 59 | random(seed=inventory_hostname) }}"
38-
39-
4038
borg_version: false
41-
borgmatic_version: false
39+
borgmatic_version: false
40+
borg_install_method: pip

molecule/default/Dockerfile.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ ENV {{ var }} {{ value }}
1414
{% endfor %}
1515
{% endif %}
1616

17-
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \
17+
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python3 python3-pip sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean; \
1818
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \
1919
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
2020
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \
2121
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
22-
elif [ $(command -v pacman) ]; then pacman --noconfirm -Suy python sudo openssh; \
22+
elif [ $(command -v pacman) ]; then pacman --noconfirm -Suy python python-pip sudo openssh; \
2323
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi

molecule/default/converge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- name: users
3939
hostname: database1.example.org
4040
port: 5433
41+
borg_install_method: pip
4142

4243
post_tasks:
4344
- name: Install yamllint for checking config file

tasks/Archlinux.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tasks/Debian.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tasks/RedHat.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tasks/install_package.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Check if EPEL repo is enabled, if installation from distro is requested
3+
when: ansible_os_family == 'RedHat'
4+
block:
5+
- name: Get list of installed packages
6+
ansible.builtin.package_facts:
7+
manager: auto
8+
- name: Ensure EPEL is enabled
9+
ansible.builtin.assert:
10+
that:
11+
- "'epel-release' in ansible_facts.packages"
12+
fail_msg: Need EPEL repo to install via distro package.
13+
14+
- name: Install borgmatic and borg via distribution package manager
15+
package:
16+
name: "{{ item }}"
17+
state: present
18+
loop: "{{ borg_distro_packages }}"

tasks/install_pip.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: Install build dependencies
3+
package:
4+
name: "{{ borg_pip_packages }}"
5+
state: present
6+
7+
- name: Create virtualenv for borg # noqa package-latest
8+
pip:
9+
name:
10+
- pip
11+
- setuptools
12+
state: latest
13+
virtualenv: /opt/borgmatic
14+
virtualenv_command: "{{ python_bin }} -m venv"
15+
16+
- name: Install dependent Python Packages
17+
pip:
18+
name: "{{ borg_dependent_python_packages }}"
19+
virtualenv: /opt/borgmatic
20+
when: borg_dependent_python_packages is defined
21+
22+
- name: Install main Python Packages
23+
pip:
24+
name: "{{ item.name }}"
25+
version: "{{ item.version | default(omit, true) }}"
26+
virtualenv: /opt/borgmatic
27+
when: borg_python_packages is defined
28+
loop: "{{ borg_python_packages }}"
29+
30+
- name: Create borgmatic command in /usr/local/bin
31+
copy:
32+
content: |
33+
#!/bin/bash
34+
. /opt/borgmatic/bin/activate
35+
borgmatic "$@"
36+
dest: /usr/local/bin/borgmatic
37+
owner: root
38+
group: root
39+
mode: "0755"

tasks/main.yml

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,14 @@
1616
- "{{ ansible_os_family }}.yml"
1717
- "{{ ansible_lsb.id }}.yml"
1818

19-
- name: Run OS-specific tasks
20-
include_tasks: "{{ item }}"
21-
with_first_found:
22-
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
23-
- "{{ ansible_os_family }}.yml"
24-
25-
- name: Install required System Packages
19+
- name: Install general dependencies (cron and openssh)
2620
package:
27-
name: "{{ borg_packages }}"
21+
name: "{{ borg_dep_packages }}"
2822
state: present
2923

30-
- name: Create virtualenv for borg # noqa package-latest
31-
pip:
32-
name:
33-
- pip
34-
- setuptools
35-
state: latest
36-
virtualenv: /opt/borgmatic
37-
virtualenv_command: "{{ python_bin }} -m venv"
38-
39-
- name: Install dependent Python Packages
40-
pip:
41-
name: "{{ borg_dependent_python_packages }}"
42-
virtualenv: /opt/borgmatic
43-
when: borg_dependent_python_packages is defined
44-
45-
- name: Install main Python Packages
46-
pip:
47-
name: "{{ item.name }}"
48-
version: "{{ item.version | default(omit, true) }}"
49-
virtualenv: /opt/borgmatic
50-
when: borg_python_packages is defined
51-
loop: "{{ borg_python_packages }}"
52-
53-
- name: Create borgmatic command in /usr/local/bin
54-
copy:
55-
content: |
56-
#!/bin/bash
57-
. /opt/borgmatic/bin/activate
58-
borgmatic "$@"
59-
dest: /usr/local/bin/borgmatic
60-
owner: root
61-
group: root
62-
mode: "0755"
24+
- name: Install Borg and Borgmatic
25+
ansible.builtin.include_tasks:
26+
file: install_{{ borg_install_method }}.yml
6327

6428
- name: Ensure root has SSH key.
6529
user:

0 commit comments

Comments
 (0)