Skip to content

Commit

Permalink
Split dep lists to avoid installing build deps when using distro pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
m3nu committed Dec 15, 2022
1 parent ed5db22 commit 85d17cf
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +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`.
- `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.
- `borg_distro_packages`: contains the names of distributions packages for `borg(backup)` and `borgmatic`, only used if `borg_install_method` is set to `package`.

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ 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_install_method: pip
borg_install_method: pip
4 changes: 2 additions & 2 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ ENV {{ var }} {{ value }}
{% endfor %}
{% endif %}

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; \
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; \
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; \
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; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v pacman) ]; then pacman --noconfirm -Suy python sudo openssh; \
elif [ $(command -v pacman) ]; then pacman --noconfirm -Suy python python-pip sudo openssh; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi
1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- name: users
hostname: database1.example.org
port: 5433
borg_install_method: pip

post_tasks:
- name: Install yamllint for checking config file
Expand Down
1 change: 0 additions & 1 deletion tasks/Archlinux.yml

This file was deleted.

1 change: 0 additions & 1 deletion tasks/Debian.yml

This file was deleted.

8 changes: 7 additions & 1 deletion tasks/RedHat.yml → tasks/install_package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Check if EPEL repo is enabled, if installation from distro is requested
when: borgmatic_install_method == 'package-manager'
when: ansible_os_family == 'RedHat'
block:
- name: Get list of installed packages
ansible.builtin.package_facts:
Expand All @@ -10,3 +10,9 @@
that:
- "'epel-release' in ansible_facts.packages"
fail_msg: Need EPEL repo to install via distro package.

- name: Install borgmatic and borg via distribution package manager
package:
name: "{{ item }}"
state: present
loop: "{{ borg_distro_packages }}"
5 changes: 5 additions & 0 deletions tasks/install_pip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
- name: Install build dependencies
package:
name: "{{ borg_pip_packages }}"
state: present

- name: Create virtualenv for borg # noqa package-latest
pip:
name:
Expand Down
6 changes: 0 additions & 6 deletions tasks/install_pkg.yml

This file was deleted.

20 changes: 4 additions & 16 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,14 @@
- "{{ ansible_os_family }}.yml"
- "{{ ansible_lsb.id }}.yml"

- name: Run OS-specific tasks
include_tasks: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family }}.yml"

- name: Install required System Packages
- name: Install general dependencies (cron and openssh)
package:
name: "{{ borg_packages }}"
name: "{{ borg_dep_packages }}"
state: present

- name: Install borgmatic via pip
ansible.builtin.include_tasks:
file: install_pip.yml
when: borgmatic_install_method == 'pip'

- name: Install borgmatic via distribution package manager
- name: Install Borg and Borgmatic
ansible.builtin.include_tasks:
file: install_pkg.yml
when: borgmatic_install_method == 'package-manager'
file: install_{{ borg_install_method }}.yml

- name: Ensure root has SSH key.
user:
Expand Down
8 changes: 5 additions & 3 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
borg_packages:
borg_dep_packages:
- cronie
- gcc
- openssh

borg_pip_packages:
- gcc
- pkgconfig
- python-pip
- python-setuptools

borg_system_packages:
borg_distro_packages:
- borg
- borgmatic

Expand Down
10 changes: 6 additions & 4 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
borg_packages:
borg_dep_packages:
- openssh-client
- cron

borg_pip_packages:
- libssl-dev
- libacl1-dev
- libacl1
Expand All @@ -10,10 +14,8 @@ borg_packages:
- python3-pkgconfig
- python3-msgpack
- python3-venv
- openssh-client
- cron

borg_system_packages:
borg_distro_packages:
- borgbackup
- borgmatic

Expand Down
10 changes: 6 additions & 4 deletions vars/Fedora.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
borg_packages:
borg_dep_packages:
- cronie
- openssh-clients

borg_pip_packages:
- libacl-devel
- libacl
- gcc
Expand All @@ -10,10 +14,8 @@ borg_packages:
- python3-devel
- python3-setuptools
- python3-Cython
- openssh-clients
- cronie

borg_system_packages:
borg_distro_packages:
- borgbackup
- borgmatic

Expand Down
17 changes: 14 additions & 3 deletions vars/ManjaroLinux.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
---
borg_packages:
- borgmatic
borg_dep_packages:
- openssh
- cronie

borg_system_packages:
borg_pip_packages: # untested
- libssl-dev
- libacl1-dev
- libacl1
- build-essential
- python3-setuptools
- python3-dev
- python3-pip
- python3-pkgconfig
- python3-msgpack
- python3-venv

borg_distro_packages:
- borg
- borgmatic

Expand Down
10 changes: 6 additions & 4 deletions vars/RedHat-8.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
borg_packages:
borg_dep_packages:
- openssh-clients
- cronie

borg_pip_packages:
- libacl-devel
- libacl
- gcc
Expand All @@ -10,10 +14,8 @@ borg_packages:
- python3-devel
- python3-setuptools
- python3-virtualenv
- openssh-clients
- cronie

borg_system_packages:
borg_distro_packages:
- borgbackup
- borgmatic

Expand Down
10 changes: 6 additions & 4 deletions vars/RedHat-9.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
borg_packages:
borg_dep_packages:
- cronie
- openssh-clients

borg_pip_packages:
- libacl-devel
- libacl
- gcc
Expand All @@ -10,10 +14,8 @@ borg_packages:
- python3-devel
- python3-setuptools
# - python3-virtualenv
- openssh-clients
- cronie

borg_system_packages:
borg_distro_packages:
- borgbackup
- borgmatic

Expand Down
10 changes: 6 additions & 4 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
borg_packages:
borg_dep_packages:
- cronie
- openssh-clients

borg_pip_packages:
- libacl-devel
- libacl
- gcc
Expand All @@ -9,10 +13,8 @@ borg_packages:
- python36-wheel
- python36-devel
- python-setuptools
- openssh-clients
- cronie

borg_system_packages:
borg_distro_packages:
- borgbackup
- borgmatic

Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
borg_dependent_python_packages:
- cython
- pkgconfig

borg_python_packages:
- name: borgbackup
version: "{{ borg_version }}"
Expand Down

0 comments on commit 85d17cf

Please sign in to comment.