From bb5b6afd4c04fb212bf4540756b05c9ded0c88c0 Mon Sep 17 00:00:00 2001 From: Manu <3916435+m3nu@users.noreply.github.com> Date: Sun, 20 Feb 2022 13:56:14 +0400 Subject: [PATCH] Add RHEL9 support, fix empty exclude option (#92) --- defaults/main.yml | 2 +- molecule/default/converge.yml | 6 ++++++ molecule/default/molecule.yml | 6 ++---- molecule/default/verify.yml | 12 +++++++++--- tasks/main.yml | 4 ++-- templates/config.yaml.j2 | 9 +++++---- vars/RedHat-9.yml | 22 ++++++++++++++++++++++ 7 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 vars/RedHat-9.yml diff --git a/defaults/main.yml b/defaults/main.yml index c3969b9..21c9961 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,6 +3,7 @@ borg_encryption_passphrase: '' borg_exclude_patterns: [] borgmatic_config_name: config.yaml borgmatic_large_repo: true +borgmatic_hooks: [] borgmatic_failure_command: - echo "`date` - Error while creating a backup." borgmatic_before_backup_command: @@ -15,7 +16,6 @@ borgmatic_check_last: 3 borgmatic_store_atime: true borgmatic_store_ctime: true borgmatic_relocated_repo_access_is_ok: false -borgmatic_hooks: [] borg_one_file_system: true borg_exclude_from: [] borg_encryption_passcommand: false diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index a8c57d5..a48969b 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -31,3 +31,9 @@ keep_daily: 7 keep_weekly: 4 keep_monthly: 6 + + post_tasks: + - name: Install yamllint for checking config file + pip: + name: yamllint + executable: pip3 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 6927d92..daf32e8 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -8,14 +8,12 @@ platforms: image: archlinux:latest - name: centos-7 image: centos:7 - - name: centos-8 - image: centos:8 + - name: almalinux-8 + image: almalinux:8 - name: fedora-latest image: fedora:latest - name: debian-bullseye image: debian:bullseye - - name: debian-buster - image: debian:buster - name: ubuntu-bionic image: ubuntu:bionic - name: ubuntu-latest diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 0736e6f..f816e3f 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -2,6 +2,12 @@ - name: Verify hosts: all tasks: - - name: Example assertion - assert: - that: true \ No newline at end of file + - name: Ensure Borgmatic is installed correctly + command: borgmatic --version + + - name: Ensure Borg is installed correctly + command: borgmatic borg --version + + - name: Ensure produced YAML is valid + command: | + yamllint -d "{extends: relaxed, rules: {line-length: {max: 120}}}" /etc/borgmatic/config.yaml diff --git a/tasks/main.yml b/tasks/main.yml index a023705..a546f5f 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -82,14 +82,14 @@ {% endif %} when: create_repo -- name: Ensures /etc/borgmatic exists +- name: Ensure /etc/borgmatic exists file: path: /etc/borgmatic state: directory mode: 0700 owner: root -- name: Add Borgmatic Configuration +- name: Add Borgmatic configuration template: src: config.yaml.j2 dest: "/etc/borgmatic/{{ borgmatic_config_name }}" diff --git a/templates/config.yaml.j2 b/templates/config.yaml.j2 index f77fd61..9f56d8b 100644 --- a/templates/config.yaml.j2 +++ b/templates/config.yaml.j2 @@ -1,4 +1,5 @@ #jinja2: lstrip_blocks: "True", trim_blocks: "True" +--- # Full config: https://torsion.org/borgmatic/docs/reference/config.yaml location: source_directories: @@ -23,7 +24,7 @@ location: # Store ctime into archive. ctime: {{ borgmatic_store_ctime }} -{% if borg_exclude_patterns|length %} +{% if borg_exclude_patterns %} # Any paths matching these patterns are excluded from backups. Globs and tildes # are expanded. See the output of "borg help patterns" for more details. exclude_patterns: @@ -31,8 +32,7 @@ location: - '{{ dir }}' {% endfor %} {% endif %} - -{% if borg_exclude_from|length %} +{% if borg_exclude_from %} # Read exclude patterns from one or more separate named files, one pattern per # line. See the output of "borg help patterns" for more details. exclude_from: @@ -196,5 +196,6 @@ hooks: {% endfor %} {% for hook in borgmatic_hooks %} - {{ hook }}: {{ borgmatic_hooks[hook] }} + {{ hook }}: + {{ borgmatic_hooks[hook] | to_nice_yaml(indent=2) | trim | indent(8) }} {% endfor %} diff --git a/vars/RedHat-9.yml b/vars/RedHat-9.yml new file mode 100644 index 0000000..54366d9 --- /dev/null +++ b/vars/RedHat-9.yml @@ -0,0 +1,22 @@ +--- +borg_packages: + - libacl-devel + - libacl + - gcc + - gcc-c++ + - openssl-devel + - python3-pip + - python3-wheel + - python3-devel + - python3-setuptools + - python3-virtualenv + - openssh-clients + - cronie + +python_bin: python3 +pip_bin: pip3 + +borg_python_packages: + - cython + - borgbackup + - borgmatic