1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic_archiver.git synced 2024-08-16 10:09:49 +02:00

Cleanup linting and prepare update

This commit is contained in:
L3D 2023-10-22 20:33:44 +02:00
parent 0c96ce2b90
commit 95d21b7d28
No known key found for this signature in database
GPG key ID: AD65B920933B4B20
16 changed files with 163 additions and 177 deletions

View file

@ -2,21 +2,21 @@
name: Ansible Lint check
# yamllint disable-line rule:truthy
on:
push:
branches: '*'
pull_request:
branches: '*'
on: [push, pull_request]
jobs:
build:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@v6
- name: 'checkout git repo'
uses: actions/checkout@v4
with:
targets: "."
submodules: true
fetch-depth: 0
- name: Run ansible-lint
uses: ansible-actions/ansible-lint-action@v1.0.1
with:
target: "./"

View file

@ -1,20 +1,24 @@
---
name: Galaxy release
name: Galaxy-NG Roles Import
# yamllint disable-line rule:truthy
on:
push:
branches: ['main']
release:
types: ['created']
jobs:
build:
name: Galaxy Role Importer
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: galaxy
uses: robertdebock/galaxy-action@1.2.1
- name: 'Checkout git repo'
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: 'Release on galaxy'
uses: ansible-actions/ansible-galaxy-action@v1.0.1
with:
galaxy_api_key: ${{ secrets.galaxy_api_key }}

View file

@ -1,22 +0,0 @@
---
name: 'Yamllint GitHub Actions'
# yamllint disable-line rule:truthy
on:
push:
branches: '*'
pull_request:
branches: '*'
jobs:
yamllint:
name: 'Yamllint'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- name: 'Yamllint'
uses: karancode/yamllint-github-action@master
with:
yamllint_file_or_dir: '.'
yamllint_config_filepath: './.yamllint'

View file

@ -1,17 +1,17 @@
---
- name: systemctl daemon-reload
- name: Run systemctl daemon-reload
become: true
ansible.builtin.systemd:
daemon_reload: true
- name: systemctl start restic-archiver.timer
- name: Run systemctl start restic-archiver.timer
become: true
ansible.builtin.systemd:
name: restic-archiver.timer
enabled: true
state: started
- name: systemctl enable restic-archiver.service
- name: Run systemctl enable restic-archiver.service
become: true
ansible.builtin.systemd:
name: restic-archiver.service

View file

@ -1,18 +1,19 @@
---
galaxy_info:
role_name: restic_archiver
author: L3D
namespace: do1jlr
author: do1jlr
namespace: l3d
description: Role to deploy restic and setup backups.
license: MIT
min_ansible_version: 2.11
min_ansible_version: "2.13"
platforms:
- name: Debian
versions: all
versions: ['all']
galaxy_tags:
- backup
- archive
- delete
- restic
- linux
dependencies: []

View file

@ -1,17 +1,17 @@
---
- name: install cron
- name: Install cron
become: true
ansible.builtin.package:
name: "{{ restic_archiver__package }}"
state: present
- name: migrate cronjob to cron.d directory
- name: Migrate cronjob to cron.d directory
become: true
ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver"
state: absent
- name: setup cronjob for restic with logging
- name: Setup cronjob for restic with logging
become: true
ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver"
@ -22,7 +22,7 @@
user: "{{ restic_archiver__owner }}"
when: restic_archiver__log_output
- name: setup cronjob for restic without logging
- name: Setup cronjob for restic without logging
become: true
ansible.builtin.cron:
name: "archive restic backup with ansible_role_restic_archiver"

View file

@ -1,9 +1,7 @@
---
# tasks file for skeleton
- name: reformat dict if necessary
- name: Reformat dict if necessary
ansible.builtin.set_fact:
restic_archiver__backups: "{{ restic_archiver__backups|dict2items|json_query('[*].value') }}"
restic_archiver__backups: "{{ restic_archiver__backups | dict2items | json_query('[*].value') }}"
when:
- restic_archiver__backups | type_debug == "dict"

View file

@ -1,5 +1,5 @@
---
- name: create /var/log/restic/
- name: Create /var/log/restic/
become: true
ansible.builtin.file:
path: /var/log/restic
@ -9,14 +9,14 @@
owner: "{{ restic_archiver__group }}"
mode: 0750
- name: install logrotate
- name: Install logrotate
become: true
ansible.builtin.package:
name: logrotate
state: present
when: restic_archiver__logrotate | bool
- name: create logrotate config
- name: Create logrotate config
become: true
ansible.builtin.copy:
src: files/logrotate.conf

View file

@ -1,5 +1,5 @@
---
- name: install requirements
- name: Install requirements
become: true
ansible.builtin.package:
name:

View file

@ -1,9 +1,9 @@
---
- name: run optional versionscheck
- name: Run optional versionscheck
ansible.builtin.include_tasks: versioncheck.yml
when: submodules_versioncheck|bool
when: submodules_versioncheck | bool
- name: deploy restic template
- name: Deploy restic template
ansible.builtin.template:
src: templates/restic_forget_snapshots.j2
dest: /opt/restic-backup.sh
@ -12,18 +12,18 @@
mode: 0700
become: true
- name: setup logrotate
- name: Setup logrotate
ansible.builtin.include_tasks: logs.yml
when: restic_archiver__log_output | bool
- name: create cronjob
- name: Create cronjob
ansible.builtin.include_tasks: cron.yml
when: not restic_archiver__use_systemd_timer | bool
- name: create systemd timer
- name: Create systemd timer
ansible.builtin.include_tasks: systemd.yml
when: restic_archiver__use_systemd_timer | bool
- name: install requirements for mailing
- name: Install requirements for mailing
ansible.builtin.include_tasks: mail.yml
when: restic_archiver__mailsummary | bool

View file

@ -1,5 +1,5 @@
---
- name: create restic-archiver.service
- name: Create restic-archiver.service
become: true
ansible.builtin.template:
src: templates/restic-archiver.service.j2
@ -8,10 +8,10 @@
owner: root
group: root
notify:
- systemctl daemon-reload
- systemctl enable restic-archiver.service
- Run systemctl daemon-reload
- Run systemctl enable restic-archiver.service
- name: create restic-archiver.timer
- name: Create restic-archiver.timer
become: true
ansible.builtin.template:
src: templates/restic-archiver.timer.j2
@ -20,5 +20,5 @@
owner: root
group: root
notify:
- systemctl daemon-reload
- systemctl start restic-archiver.timer
- Run systemctl daemon-reload
- Run systemctl start restic-archiver.timer

View file

@ -8,37 +8,38 @@
path: '/etc/.ansible-version'
state: directory
mode: 0755
when: submodules_versioncheck|bool
when: submodules_versioncheck | bool
- name: check playbook version
- name: Check playbook version
become: true
ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck|bool
when: submodules_versioncheck | bool
ignore_errors: true
failed_when: false
- name: Print remote role version
ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: submodules_versioncheck|bool
when: submodules_versioncheck | bool
- name: Print locale role version
ansible.builtin.debug:
msg: "Local role version: '{{ playbook_version_number|string }}'."
when: submodules_versioncheck|bool
msg: "Local role version: '{{ playbook_version_number | string }}'."
when: submodules_versioncheck | bool
- name: Check if your version is outdated
ansible.builtin.fail:
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
when:
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck|bool
- playbook_version.content|default("Mgo=")|b64decode|int - 1 >= playbook_version_number|int and submodules_versioncheck | bool
- name: write new version to remote disk
- name: Write new version to remote disk
become: true
ansible.builtin.copy:
content: "{{ playbook_version_number }}"
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
mode: '0644'
when: submodules_versioncheck|bool
when: submodules_versioncheck | bool
tags: skip_ansible_lint_template-instead-of-copy

View file

@ -4,79 +4,83 @@
Variables are defined via defaults!
#}
{% macro retention_pattern(repo) -%}
{% if repo.keep_last is defined and repo.keep_last != None -%}
--keep-last {{ repo.keep_last }}
{%- else -%}
--keep-last {{ restic_archiver__keep }}
{%- endif %} \
{% if repo.keep_hourly is defined and repo.keep_hourly != None -%}
--keep-hourly {{ repo.keep_hourly }}
{%- else -%}
--keep-hourly {{ restic_archiver__keep_hourly }}
{%- endif %} \
{% if repo.keep_daily is defined and repo.keep_daily != None -%}
--keep-daily {{ repo.keep_daily }}
{%- else -%}
--keep-daily {{ restic_archiver__keep_daily }}
{%- endif %} \
{% if repo.keep_weekly is defined and repo.keep_weekly != None -%}
--keep-weekly {{ repo.keep_weekly }}
{%- else -%}
--keep-weekly {{ restic_archiver__keep_weekly }}
{%- endif %} \
{% if repo.keep_monthly is defined and repo.keep_monthly != None -%}
--keep-monthly {{ repo.keep_monthly }}
{%- else -%}
--keep-monthly {{ restic_archiver__keep_monthly }}
{%- endif %} \
{% if repo.keep_yearly is defined and repo.keep_yearly != None -%}
--keep-yearly {{ repo.keep_yearly }}
{%- else -%}
--keep-yearly {{ restic_archiver__keep_yearly }}
{%- endif -%}
{% if repo.keep_within is defined and repo.keep_within != None %} \
--keep-within {{ repo.keep_within }} {% endif -%}
{%- if repo.prune|default(restic_archiver__prune) %} \
--prune {% endif %}
{%- endmacro %}
{% macro retention_pattern(repo) %}
{% if repo.keep_last is defined and repo.keep_last != None %}
--keep-last {{ repo.keep_last }} \
{% else %}
--keep-last {{ restic_archiver__keep }} \
{% endif %}
{% if repo.keep_hourly is defined and repo.keep_hourly != None %}
--keep-hourly {{ repo.keep_hourly }} \
{% else %}
--keep-hourly {{ restic_archiver__keep_hourly }} \
{% endif %}
{% if repo.keep_daily is defined and repo.keep_daily != None %}
--keep-daily {{ repo.keep_daily }} \
{% else %}
--keep-daily {{ restic_archiver__keep_daily }} \
{% endif %}
{% if repo.keep_weekly is defined and repo.keep_weekly != None %}
--keep-weekly {{ repo.keep_weekly }} \
{% else %}
--keep-weekly {{ restic_archiver__keep_weekly }} \
{% endif %}
{% if repo.keep_monthly is defined and repo.keep_monthly != None %}
--keep-monthly {{ repo.keep_monthly }} \
{% else %}
--keep-monthly {{ restic_archiver__keep_monthly }} \
{% endif %}
{% if repo.keep_yearly is defined and repo.keep_yearly != None %}
--keep-yearly {{ repo.keep_yearly }} \
{% else %}
--keep-yearly {{ restic_archiver__keep_yearly }} \
{% endif %}
{% if repo.keep_within is defined and repo.keep_within != None %}
--keep-within {{ repo.keep_within }} \
{% endif %}
{% if repo.prune | default(restic_archiver__prune) %}
--prune
{% endif %}
{% endmacro %}
{% macro retention_archive_pattern(repo) -%}
{% if repo.keep_last is defined and repo.archive_keep_last != None -%}
--keep-last {{ repo.archive_keep_last }}
{%- else -%}
--keep-last {{ restic_archiver__archive_keep }}
{%- endif %} \
{% if repo.keep_hourly is defined and repo.archive_keep_hourly != None -%}
--keep-hourly {{ repo.archive_keep_hourly }}
{%- else -%}
--keep-hourly {{ restic_archiver__archive_keep_hourly }}
{%- endif %} \
{% if repo.keep_daily is defined and repo.archive_keep_daily != None -%}
--keep-daily {{ repo.archive_keep_daily }}
{%- else -%}
--keep-daily {{ restic_archiver__archive_keep_daily }}
{%- endif %} \
{% if repo.keep_weekly is defined and repo.archive_keep_weekly != None -%}
--keep-weekly {{ repo.archive_keep_weekly }}
{%- else -%}
--keep-weekly {{ restic_archiver__archive_keep_weekly }}
{%- endif %} \
{% if repo.keep_monthly is defined and repo.archive_keep_monthly != None -%}
--keep-monthly {{ repo.archive_keep_monthly }}
{%- else -%}
{% macro retention_archive_pattern(repo) %}
{% if repo.keep_last is defined and repo.archive_keep_last != None %}
--keep-last {{ repo.archive_keep_last }} \
{% else %}
--keep-last {{ restic_archiver__archive_keep }} \
{% endif %}
{% if repo.keep_hourly is defined and repo.archive_keep_hourly != None %}
--keep-hourly {{ repo.archive_keep_hourly }} \
{% else %}
--keep-hourly {{ restic_archiver__archive_keep_hourly }} \
{% endif %}
{% if repo.keep_daily is defined and repo.archive_keep_daily != None %}
--keep-daily {{ repo.archive_keep_daily }} \
{% else %}
--keep-daily {{ restic_archiver__archive_keep_daily }} \
{% endif %}
{% if repo.keep_weekly is defined and repo.archive_keep_weekly != None %}
--keep-weekly {{ repo.archive_keep_weekly }} \
{% else %}
--keep-weekly {{ restic_archiver__archive_keep_weekly }} \
{% endif %}
{% if repo.keep_monthly is defined and repo.archive_keep_monthly != None %}
--keep-monthly {{ repo.archive_keep_monthly }} \
{% else %}
--keep-monthly {{ restic_archiver__archive_keep_monthly }}
{%- endif %} \
{% if repo.keep_yearly is defined and repo.archive_keep_yearly != None -%}
{% endif %}
{% if repo.keep_yearly is defined and repo.archive_keep_yearly != None %}
--keep-yearly {{ repo.archive_keep_yearly }}
{%- else -%}
{% else %}
--keep-yearly {{ restic_archiver__archive_keep_yearly }}
{%- endif -%}
{% if repo.keep_within is defined and repo.archive_keep_within != None %} \
--keep-within {{ repo.archive_keep_within }} {% endif -%}
{%- if repo.prune|default(restic_archiver__prune) %} \
--prune {% endif %}
{%- endmacro %}
{% endif %}
{% if repo.keep_within is defined and repo.archive_keep_within != None %} \
--keep-within {{ repo.archive_keep_within }}
{% endif %}
{% if repo.prune | default(restic_archiver__prune) %}
--prune
{% endif %}
{% endmacro %}
{#
@ -103,7 +107,7 @@ START DOING STUFF INSIDE THE RESTIC REPO FOR LOOP
echo "init $BACKUP_NAME"
restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }}
echo "restic forget done"
{% if repo.prune|default(restic_archiver__prune) %}
{% if repo.prune | default(restic_archiver__prune) %}
restic {{ restic_archiver__default_opt }} prune
echo "restic prune done"
{% endif %}
@ -141,7 +145,7 @@ EOT
restic {{ restic_archiver__default_opt }} check
{% endif %}
{% if repo.archive|default(false) %}
{% if repo.archive | default(false) %}
# ARCHIVE Settings for Server "{{ repo['name'] | string }}"
export RESTIC_REPOSITORY="{{ repo['archive_location'] }}"
export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
@ -176,7 +180,7 @@ EOT
BACKUP_NAME="{{ repo.name }}_archive"
restic {{ restic_archiver__default_opt }} forget {{ retention_archive_pattern(repo) }}
{% if repo.prune|default(restic_archiver__prune) %}
{% if repo.prune | default(restic_archiver__prune) %}
restic {{ restic_archiver__default_opt }} prune
echo "restic ARCHIVE prune done"
{% endif %}
@ -192,7 +196,7 @@ EOT
{% endif %}
} || { # catch
} | | { # catch
echo -e "<h1>ALARM, ALARM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>" >> /tmp/mailcontent
awk 'NR==3{print "<h1>ALARM, ALARM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>"}1' /tmp/mailcontent >> /tmp/mailcontentx
mv /tmp/mailcontentx /tmp/mailcontent

View file

@ -6,6 +6,6 @@ Documentation=https://github.com/roles-ansible/ansible_role_restic_archiver.git
Type=oneshot
ExecStart=/opt/restic-backup.sh
TimeoutStartSec=0
{% if restic_archiver__log_output -%}
{% if restic_archiver__log_output %}
StandardOutput=append:/var/log/restic/restic_archiver.log
{%- endif -%}
{% endif %}

View file

@ -18,25 +18,25 @@ fi
{% if restic_archiver__cache_config | bool %}
{% include 'includes/restic_cache.sh.j2' %}
{% include 'includes/restic_cache.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_on_error | bool %}
{% include 'includes/set_send_mail_on_error_variable.sh.j2' %}
{% include 'includes/set_send_mail_on_error_variable.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_header.sh.j2' %}
{% include 'includes/mail_report_header.sh.j2' %}
{% endif %}
{% for repo in restic_archiver__repos %}
{% include 'includes/repo_todos.sh.j2' %}
{% include 'includes/repo_todos.sh.j2' %}
{% endfor %}
sync
{% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_trailer.sh.j2' %}
{% include 'includes/mail_report_trailer.sh.j2' %}
{% endif %}
{% if restic_archiver__mail_on_error | bool %}

View file

@ -1,3 +1,3 @@
---
playbook_version_number: 54 # should be int
playbook_version_number: 55 # should be int
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'