mirror of
https://github.com/borgbase/ansible-role-borgbackup.git
synced 2024-11-19 19:07:42 +01:00
Allow to installation via OS package manager or pip (#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 <dev@morgenthaler.at> Co-authored-by: Manu <manu@snapdragon.cc>
This commit is contained in:
parent
e34f9311d8
commit
981d4f9072
@ -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
|
||||
|
||||
- `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
|
||||
|
||||
|
@ -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
|
||||
borg_install_method: pip
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1 +0,0 @@
|
||||
---
|
@ -1 +0,0 @@
|
||||
---
|
@ -1 +0,0 @@
|
||||
---
|
18
tasks/install_package.yml
Normal file
18
tasks/install_package.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
- name: Check if EPEL repo is enabled, if installation from distro is requested
|
||||
when: ansible_os_family == 'RedHat'
|
||||
block:
|
||||
- name: Get list of installed packages
|
||||
ansible.builtin.package_facts:
|
||||
manager: auto
|
||||
- name: Ensure EPEL is enabled
|
||||
ansible.builtin.assert:
|
||||
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 }}"
|
39
tasks/install_pip.yml
Normal file
39
tasks/install_pip.yml
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
- name: Install build dependencies
|
||||
package:
|
||||
name: "{{ borg_pip_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 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"
|
@ -16,50 +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: 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"
|
||||
- name: Install Borg and Borgmatic
|
||||
ansible.builtin.include_tasks:
|
||||
file: install_{{ borg_install_method }}.yml
|
||||
|
||||
- name: Ensure root has SSH key.
|
||||
user:
|
||||
|
@ -1,11 +1,17 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- cronie
|
||||
- gcc
|
||||
- openssh
|
||||
|
||||
borg_pip_packages:
|
||||
- gcc
|
||||
- pkgconfig
|
||||
- python-pip
|
||||
- python-setuptools
|
||||
|
||||
borg_distro_packages:
|
||||
- borg
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,5 +1,9 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- openssh-client
|
||||
- cron
|
||||
|
||||
borg_pip_packages:
|
||||
- libssl-dev
|
||||
- libacl1-dev
|
||||
- libacl1
|
||||
@ -10,8 +14,10 @@ borg_packages:
|
||||
- python3-pkgconfig
|
||||
- python3-msgpack
|
||||
- python3-venv
|
||||
- openssh-client
|
||||
- cron
|
||||
|
||||
borg_distro_packages:
|
||||
- borgbackup
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,5 +1,9 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- cronie
|
||||
- openssh-clients
|
||||
|
||||
borg_pip_packages:
|
||||
- libacl-devel
|
||||
- libacl
|
||||
- gcc
|
||||
@ -10,8 +14,10 @@ borg_packages:
|
||||
- python3-devel
|
||||
- python3-setuptools
|
||||
- python3-Cython
|
||||
- openssh-clients
|
||||
- cronie
|
||||
|
||||
borg_distro_packages:
|
||||
- borgbackup
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,8 +1,23 @@
|
||||
---
|
||||
borg_packages:
|
||||
- borgmatic
|
||||
borg_dep_packages:
|
||||
- openssh
|
||||
- cronie
|
||||
|
||||
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
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,5 +1,9 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- openssh-clients
|
||||
- cronie
|
||||
|
||||
borg_pip_packages:
|
||||
- libacl-devel
|
||||
- libacl
|
||||
- gcc
|
||||
@ -10,8 +14,10 @@ borg_packages:
|
||||
- python3-devel
|
||||
- python3-setuptools
|
||||
- python3-virtualenv
|
||||
- openssh-clients
|
||||
- cronie
|
||||
|
||||
borg_distro_packages:
|
||||
- borgbackup
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,5 +1,9 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- cronie
|
||||
- openssh-clients
|
||||
|
||||
borg_pip_packages:
|
||||
- libacl-devel
|
||||
- libacl
|
||||
- gcc
|
||||
@ -10,8 +14,10 @@ borg_packages:
|
||||
- python3-devel
|
||||
- python3-setuptools
|
||||
# - python3-virtualenv
|
||||
- openssh-clients
|
||||
- cronie
|
||||
|
||||
borg_distro_packages:
|
||||
- borgbackup
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -1,5 +1,9 @@
|
||||
---
|
||||
borg_packages:
|
||||
borg_dep_packages:
|
||||
- cronie
|
||||
- openssh-clients
|
||||
|
||||
borg_pip_packages:
|
||||
- libacl-devel
|
||||
- libacl
|
||||
- gcc
|
||||
@ -9,8 +13,10 @@ borg_packages:
|
||||
- python36-wheel
|
||||
- python36-devel
|
||||
- python-setuptools
|
||||
- openssh-clients
|
||||
- cronie
|
||||
|
||||
borg_distro_packages:
|
||||
- borgbackup
|
||||
- borgmatic
|
||||
|
||||
python_bin: python3
|
||||
pip_bin: pip3
|
||||
|
@ -2,6 +2,7 @@
|
||||
borg_dependent_python_packages:
|
||||
- cython
|
||||
- pkgconfig
|
||||
|
||||
borg_python_packages:
|
||||
- name: borgbackup
|
||||
version: "{{ borg_version }}"
|
||||
|
Loading…
Reference in New Issue
Block a user