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 name: Ansible Lint check
# yamllint disable-line rule:truthy # yamllint disable-line rule:truthy
on: on: [push, pull_request]
push:
branches: '*'
pull_request:
branches: '*'
jobs: jobs:
build: build:
name: Ansible Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - name: 'checkout git repo'
uses: actions/checkout@v4
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@v6
with: 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 # yamllint disable-line rule:truthy
on: on:
push:
branches: ['main']
release: release:
types: ['created'] types: ['created']
jobs: jobs:
build: build:
name: Galaxy Role Importer
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: checkout - name: 'Checkout git repo'
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: galaxy with:
uses: robertdebock/galaxy-action@1.2.1 submodules: true
fetch-depth: 0
- name: 'Release on galaxy'
uses: ansible-actions/ansible-galaxy-action@v1.0.1
with: with:
galaxy_api_key: ${{ secrets.galaxy_api_key }} 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 become: true
ansible.builtin.systemd: ansible.builtin.systemd:
daemon_reload: true daemon_reload: true
- name: systemctl start restic-archiver.timer - name: Run systemctl start restic-archiver.timer
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: restic-archiver.timer name: restic-archiver.timer
enabled: true enabled: true
state: started state: started
- name: systemctl enable restic-archiver.service - name: Run systemctl enable restic-archiver.service
become: true become: true
ansible.builtin.systemd: ansible.builtin.systemd:
name: restic-archiver.service name: restic-archiver.service

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,37 +8,38 @@
path: '/etc/.ansible-version' path: '/etc/.ansible-version'
state: directory state: directory
mode: 0755 mode: 0755
when: submodules_versioncheck|bool when: submodules_versioncheck | bool
- name: check playbook version - name: Check playbook version
become: true become: true
ansible.builtin.slurp: ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ playbook_version_path }}" src: "/etc/.ansible-version/{{ playbook_version_path }}"
register: playbook_version register: playbook_version
when: submodules_versioncheck|bool when: submodules_versioncheck | bool
ignore_errors: true ignore_errors: true
failed_when: false failed_when: false
- name: Print remote role version - name: Print remote role version
ansible.builtin.debug: ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}" msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: submodules_versioncheck|bool when: submodules_versioncheck | bool
- name: Print locale role version - name: Print locale role version
ansible.builtin.debug: ansible.builtin.debug:
msg: "Local role version: '{{ playbook_version_number|string }}'." msg: "Local role version: '{{ playbook_version_number | string }}'."
when: submodules_versioncheck|bool when: submodules_versioncheck | bool
- name: Check if your version is outdated - name: Check if your version is outdated
ansible.builtin.fail: ansible.builtin.fail:
msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!" msg: "Your ansible module has the version '{{ playbook_version_number }}' and is outdated. You need to update it!"
when: 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 become: true
ansible.builtin.copy: ansible.builtin.copy:
content: "{{ playbook_version_number }}" content: "{{ playbook_version_number }}"
dest: "/etc/.ansible-version/{{ playbook_version_path }}" dest: "/etc/.ansible-version/{{ playbook_version_path }}"
mode: '0644' 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! Variables are defined via defaults!
#} #}
{% macro retention_pattern(repo) -%} {% macro retention_pattern(repo) %}
{% if repo.keep_last is defined and repo.keep_last != None -%} {% if repo.keep_last is defined and repo.keep_last != None %}
--keep-last {{ repo.keep_last }} --keep-last {{ repo.keep_last }} \
{%- else -%} {% else %}
--keep-last {{ restic_archiver__keep }} --keep-last {{ restic_archiver__keep }} \
{%- endif %} \ {% endif %}
{% if repo.keep_hourly is defined and repo.keep_hourly != None -%} {% if repo.keep_hourly is defined and repo.keep_hourly != None %}
--keep-hourly {{ repo.keep_hourly }} --keep-hourly {{ repo.keep_hourly }} \
{%- else -%} {% else %}
--keep-hourly {{ restic_archiver__keep_hourly }} --keep-hourly {{ restic_archiver__keep_hourly }} \
{%- endif %} \ {% endif %}
{% if repo.keep_daily is defined and repo.keep_daily != None -%} {% if repo.keep_daily is defined and repo.keep_daily != None %}
--keep-daily {{ repo.keep_daily }} --keep-daily {{ repo.keep_daily }} \
{%- else -%} {% else %}
--keep-daily {{ restic_archiver__keep_daily }} --keep-daily {{ restic_archiver__keep_daily }} \
{%- endif %} \ {% endif %}
{% if repo.keep_weekly is defined and repo.keep_weekly != None -%} {% if repo.keep_weekly is defined and repo.keep_weekly != None %}
--keep-weekly {{ repo.keep_weekly }} --keep-weekly {{ repo.keep_weekly }} \
{%- else -%} {% else %}
--keep-weekly {{ restic_archiver__keep_weekly }} --keep-weekly {{ restic_archiver__keep_weekly }} \
{%- endif %} \ {% endif %}
{% if repo.keep_monthly is defined and repo.keep_monthly != None -%} {% if repo.keep_monthly is defined and repo.keep_monthly != None %}
--keep-monthly {{ repo.keep_monthly }} --keep-monthly {{ repo.keep_monthly }} \
{%- else -%} {% else %}
--keep-monthly {{ restic_archiver__keep_monthly }} --keep-monthly {{ restic_archiver__keep_monthly }} \
{%- endif %} \ {% endif %}
{% if repo.keep_yearly is defined and repo.keep_yearly != None -%} {% if repo.keep_yearly is defined and repo.keep_yearly != None %}
--keep-yearly {{ repo.keep_yearly }} --keep-yearly {{ repo.keep_yearly }} \
{%- else -%} {% else %}
--keep-yearly {{ restic_archiver__keep_yearly }} --keep-yearly {{ restic_archiver__keep_yearly }} \
{%- endif -%} {% endif %}
{% if repo.keep_within is defined and repo.keep_within != None %} \ {% if repo.keep_within is defined and repo.keep_within != None %}
--keep-within {{ repo.keep_within }} {% endif -%} --keep-within {{ repo.keep_within }} \
{%- if repo.prune|default(restic_archiver__prune) %} \ {% endif %}
--prune {% endif %} {% if repo.prune | default(restic_archiver__prune) %}
{%- endmacro %} --prune
{% endif %}
{% endmacro %}
{% macro retention_archive_pattern(repo) -%} {% macro retention_archive_pattern(repo) %}
{% if repo.keep_last is defined and repo.archive_keep_last != None -%} {% if repo.keep_last is defined and repo.archive_keep_last != None %}
--keep-last {{ repo.archive_keep_last }} --keep-last {{ repo.archive_keep_last }} \
{%- else -%} {% else %}
--keep-last {{ restic_archiver__archive_keep }} --keep-last {{ restic_archiver__archive_keep }} \
{%- endif %} \ {% endif %}
{% if repo.keep_hourly is defined and repo.archive_keep_hourly != None -%} {% if repo.keep_hourly is defined and repo.archive_keep_hourly != None %}
--keep-hourly {{ repo.archive_keep_hourly }} --keep-hourly {{ repo.archive_keep_hourly }} \
{%- else -%} {% else %}
--keep-hourly {{ restic_archiver__archive_keep_hourly }} --keep-hourly {{ restic_archiver__archive_keep_hourly }} \
{%- endif %} \ {% endif %}
{% if repo.keep_daily is defined and repo.archive_keep_daily != None -%} {% if repo.keep_daily is defined and repo.archive_keep_daily != None %}
--keep-daily {{ repo.archive_keep_daily }} --keep-daily {{ repo.archive_keep_daily }} \
{%- else -%} {% else %}
--keep-daily {{ restic_archiver__archive_keep_daily }} --keep-daily {{ restic_archiver__archive_keep_daily }} \
{%- endif %} \ {% endif %}
{% if repo.keep_weekly is defined and repo.archive_keep_weekly != None -%} {% if repo.keep_weekly is defined and repo.archive_keep_weekly != None %}
--keep-weekly {{ repo.archive_keep_weekly }} --keep-weekly {{ repo.archive_keep_weekly }} \
{%- else -%} {% else %}
--keep-weekly {{ restic_archiver__archive_keep_weekly }} --keep-weekly {{ restic_archiver__archive_keep_weekly }} \
{%- endif %} \ {% endif %}
{% if repo.keep_monthly is defined and repo.archive_keep_monthly != None -%} {% if repo.keep_monthly is defined and repo.archive_keep_monthly != None %}
--keep-monthly {{ repo.archive_keep_monthly }} --keep-monthly {{ repo.archive_keep_monthly }} \
{%- else -%} {% else %}
--keep-monthly {{ restic_archiver__archive_keep_monthly }} --keep-monthly {{ restic_archiver__archive_keep_monthly }}
{%- endif %} \ {% endif %}
{% if repo.keep_yearly is defined and repo.archive_keep_yearly != None -%} {% if repo.keep_yearly is defined and repo.archive_keep_yearly != None %}
--keep-yearly {{ repo.archive_keep_yearly }} --keep-yearly {{ repo.archive_keep_yearly }}
{%- else -%} {% else %}
--keep-yearly {{ restic_archiver__archive_keep_yearly }} --keep-yearly {{ restic_archiver__archive_keep_yearly }}
{%- endif -%} {% endif %}
{% if repo.keep_within is defined and repo.archive_keep_within != None %} \ {% if repo.keep_within is defined and repo.archive_keep_within != None %} \
--keep-within {{ repo.archive_keep_within }} {% endif -%} --keep-within {{ repo.archive_keep_within }}
{%- if repo.prune|default(restic_archiver__prune) %} \ {% endif %}
--prune {% endif %} {% if repo.prune | default(restic_archiver__prune) %}
{%- endmacro %} --prune
{% endif %}
{% endmacro %}
{# {#
@ -103,7 +107,7 @@ START DOING STUFF INSIDE THE RESTIC REPO FOR LOOP
echo "init $BACKUP_NAME" echo "init $BACKUP_NAME"
restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }} restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }}
echo "restic forget done" echo "restic forget done"
{% if repo.prune|default(restic_archiver__prune) %} {% if repo.prune | default(restic_archiver__prune) %}
restic {{ restic_archiver__default_opt }} prune restic {{ restic_archiver__default_opt }} prune
echo "restic prune done" echo "restic prune done"
{% endif %} {% endif %}
@ -141,7 +145,7 @@ EOT
restic {{ restic_archiver__default_opt }} check restic {{ restic_archiver__default_opt }} check
{% endif %} {% endif %}
{% if repo.archive|default(false) %} {% if repo.archive | default(false) %}
# ARCHIVE Settings for Server "{{ repo['name'] | string }}" # ARCHIVE Settings for Server "{{ repo['name'] | string }}"
export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" export RESTIC_REPOSITORY="{{ repo['archive_location'] }}"
export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
@ -176,7 +180,7 @@ EOT
BACKUP_NAME="{{ repo.name }}_archive" BACKUP_NAME="{{ repo.name }}_archive"
restic {{ restic_archiver__default_opt }} forget {{ retention_archive_pattern(repo) }} 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 restic {{ restic_archiver__default_opt }} prune
echo "restic ARCHIVE prune done" echo "restic ARCHIVE prune done"
{% endif %} {% endif %}
@ -192,7 +196,7 @@ EOT
{% endif %} {% endif %}
} || { # catch } | | { # catch
echo -e "<h1>ALARM, ALARM</h1>\n<h2>SOMETING IN $RESTIC_REPOSITORY went wrong</h2>" >> /tmp/mailcontent 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 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 mv /tmp/mailcontentx /tmp/mailcontent

View file

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

View file

@ -18,25 +18,25 @@ fi
{% if restic_archiver__cache_config | bool %} {% if restic_archiver__cache_config | bool %}
{% include 'includes/restic_cache.sh.j2' %} {% include 'includes/restic_cache.sh.j2' %}
{% endif %} {% endif %}
{% if restic_archiver__mail_on_error | bool %} {% 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 %} {% endif %}
{% if restic_archiver__mail_report | default(false) %} {% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_header.sh.j2' %} {% include 'includes/mail_report_header.sh.j2' %}
{% endif %} {% endif %}
{% for repo in restic_archiver__repos %} {% for repo in restic_archiver__repos %}
{% include 'includes/repo_todos.sh.j2' %} {% include 'includes/repo_todos.sh.j2' %}
{% endfor %} {% endfor %}
sync sync
{% if restic_archiver__mail_report | default(false) %} {% if restic_archiver__mail_report | default(false) %}
{% include 'includes/mail_report_trailer.sh.j2' %} {% include 'includes/mail_report_trailer.sh.j2' %}
{% endif %} {% endif %}
{% if restic_archiver__mail_on_error | bool %} {% 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' playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'