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

Merge pull request #3 from DO1JLR/restructure

combine mail template and main template
This commit is contained in:
L3D 2021-02-17 18:44:07 +01:00 committed by GitHub
commit 1ddac2d295
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 205 additions and 177 deletions

View file

@ -1,5 +1,7 @@
---
name: Ansible check debian:buster
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: ansible check with debian:buster
uses: roles-ansible/check-ansible-debian-buster-action@master
with:
targets: "./"
- name: ansible check with debian:buster
uses: roles-ansible/check-ansible-debian-buster-action@master
with:
targets: "./"

View file

@ -1,5 +1,7 @@
---
name: Ansible check debian:latest
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: ansible check with debian:latest
uses: roles-ansible/check-ansible-debian-latest-action@master
with:
targets: "./"
- name: ansible check with debian:latest
uses: roles-ansible/check-ansible-debian-latest-action@master
with:
targets: "./"

View file

@ -1,5 +1,7 @@
---
name: Ansible check debian:sid
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: ansible check with debian:sid
uses: roles-ansible/check-ansible-debian-sid-action@master
with:
targets: "./"
- name: ansible check with debian:sid
uses: roles-ansible/check-ansible-debian-sid-action@master
with:
targets: "./"

View file

@ -1,5 +1,7 @@
---
name: Ansible check debian:stable
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: ansible check with debian:stable
uses: roles-ansible/check-ansible-debian-stable-action@master
with:
targets: "./"
- name: ansible check with debian:stable
uses: roles-ansible/check-ansible-debian-stable-action@master
with:
targets: "./"

View file

@ -1,5 +1,7 @@
---
name: Ansible check debian:stretch
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,9 +10,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: ansible check with debian:stretch
uses: roles-ansible/check-ansible-debian-stretch-action@master
with:
targets: "./"
- name: ansible check with debian:stretch
uses: roles-ansible/check-ansible-debian-stretch-action@master
with:
targets: "./"

View file

@ -1,5 +1,7 @@
---
name: Ansible Lint check
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
@ -8,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@master
with:
targets: "."
# [required]
# Paths to ansible files (i.e., playbooks, tasks, handlers etc..)
args: ""
# [optional]
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@master
with:
targets: "."
# [required]
# Paths to ansible files (i.e., playbooks, tasks, handlers etc..)
args: ""
# [optional]

View file

@ -0,0 +1,18 @@
---
name: Ansible check ubuntu:latest
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ansible check with ubuntu:latest
uses: roles-ansible/check-ansible-ubuntu-latest-action@master
with:
targets: "./"

View file

@ -0,0 +1,18 @@
---
name: Ansible check ubuntu:trusty
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ansible check with ubuntu:trusty
uses: roles-ansible/check-ansible-ubuntu-trusty-action@master
with:
targets: "./"

22
.github/workflows/yamllint.yaml vendored Normal file
View file

@ -0,0 +1,22 @@
---
name: 'Yamllint GitHub Actions'
# yamllint disable-line rule:truthy
on: [push, pull_request]
jobs:
yamllint:
name: 'Yamllint'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@master
- name: 'Yamllint'
uses: karancode/yamllint-github-action@master
with:
yamllint_file_or_dir: '.'
yamllint_config_filepath: './.yamllint'
yamllint_strict: false
yamllint_comment: true
# env:
# GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }

8
.yamllint Normal file
View file

@ -0,0 +1,8 @@
---
extends: default
rules:
# 150 chars should be enough, but don't fail if a line is longer
line-length:
max: 150
level: warning

View file

@ -20,11 +20,11 @@ restic_archiver__repos: {}
# keep_within: 1
# how long should we store all backups by default
restic_archiver__keep: 9
restic_archiver__keep_hourly: 28
restic_archiver__keep_daily: 26
restic_archiver__keep: 5
restic_archiver__keep_hourly: 16
restic_archiver__keep_daily: 14
restic_archiver__keep_weekly: 8
restic_archiver__keep_monthly: 13
restic_archiver__keep_monthly: 16
restic_archiver__keep_yearly: 12
# owner and user of all restic stuff

View file

@ -26,15 +26,3 @@
minute: "{{ restic_archiver__minute }}"
user: "{{ restic_archiver__owner }}"
when: not restic_archiver__log_output
- name: setup cronjob for restic mailsummary
become: true
cron:
name: "archive restic mailsumary"
job: /opt/restic-mailsummary.sh
cron_file: /etc/crontab
hour: "7"
minute: "30"
user: "{{ restic_archiver__owner }}"
when: restic_archiver__mailsummary

View file

@ -6,13 +6,4 @@
- jq
- bsd-mailx
state: present
- name: deploy restic template
template:
src: templates/restic_mailsummary.j2
dest: /opt/restic-mailsummary.sh
group: "{{ restic_archiver__owner }}"
owner: "{{ restic_archiver__group }}"
mode: 0700
become: true
when: restic_archiver__mailsummary | bool

View file

@ -1,7 +1,7 @@
---
- name: Create directory for versionscheck
become: true
file:
ansible.builtin.file:
path: '/etc/.ansible-version'
state: directory
mode: 0755
@ -9,38 +9,38 @@
- name: check playbook version
become: true
slurp:
ansible.builtin.slurp:
src: "/etc/.ansible-version/{{ playbook_version_path }}"
register: playbook_version
when: submodules_versioncheck|bool
ignore_errors: yes
ignore_errors: true
failed_when: false
- name: Print remote role version
debug:
ansible.builtin.debug:
msg: "Remote role version: {{ playbook_version.content | default('Y3VycmVudGx5IG5vdCBkZXBsb3llZAo=') | b64decode | string }}"
when: submodules_versioncheck|bool
- name: Print locale role version
debug:
ansible.builtin.debug:
msg: "Local role version: '{{ playbook_version_number|string }}'."
when: submodules_versioncheck|bool
- name: Check if your version is outdated
fail:
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
- name: check if '/etc/ansible-version/' is empty
find:
ansible.builtin.find:
paths: '/etc/ansible-version/'
register: filesFound
- name: write new version to remote disk
become: true
copy:
ansible.builtin.copy:
content: "{{ playbook_version_number }}"
dest: "/etc/.ansible-version/{{ playbook_version_path }}"
mode: 0644
mode: '0644'
when: submodules_versioncheck|bool

View file

@ -1,6 +1,25 @@
#!/usr/bin/env bash
# {{ ansible_managed }}
# This file is to cleanup your backup archive and move some snapshots to a external storage.
{% if restic_archiver__mail_report | default(false) %}
# This file is also designed to create a overview
# over the restic backup and
# send it by mail - if wanted
cat <<EOT > /tmp/mailcontent
<!DOCTYPE html>
<html>
<head>
<title>Restic summary</title>
</head>
<body>
<h1>SUMMARY for Restic BACKUP</h1>
{{ restic_archiver__additional_mail_msg | default ('') }}
EOT
{% endif %}
{% for repo in restic_archiver__repos %}
{#
@ -71,7 +90,38 @@ BACKUP_NAME="{{ repo.name }}"
restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }}
{% if restic_archiver__mail_report | default(false) %}
cat <<EOT >> /tmp/mailcontent
<h2>{{ repo.name }}</h2>
$(restic {{ restic_archiver__default_opt }} check --quiet 2>/dev/null)
<h4>Latest Snapshots</h4>
<table style="width:100%">
<tr>
<th>Hostname</th>
<th>latest backup</th>
<th>Path</th>
</tr>
$(restic --quiet snapshots --last --json | jq -c '.[]' | while read i; do echo -e "$i" | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>', jsondata['hostname'], '</td>\n<td>', jsondata['time'], '</td>\n<td>', str(jsondata['paths'][0]), '</td>\n</tr>\n')" ; done)
</table>
<table style="width:100%">
<tr>
<th>name</th>
<th>total size</th>
<th>total files</th>
</tr>
<tr>
<td>snapshots</td>
$(restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<td>', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB </td>\n<td>', str(jsondata['total_file_count']), ' Files</td>')")
</tr>
EOT
{% else %}
restic {{ restic_archiver__default_opt }} check
{% endif %}
{% if repo.archive|default(false) %}
# ARCHIVE Settings for Server "{{ repo['name'] | string }}"
@ -81,10 +131,6 @@ export RESTIC_REPOSITORY2="{{ repo['location'] }}"
export RESTIC_PASSWORD2='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
BACKUP_NAME="{{ repo.name }}_archive"
# init repo if it does not exist
if ([ -z "$(restic cat config)" ]) 2>/dev/null; then
restic {{ restic_archiver__default_opt }} init --copy-chunker-params
fi
{% if restic_archiver__mount_required %}
set +euxo pipefail
@ -96,6 +142,11 @@ else
fi
set -euxo pipefail
{% endif %}
# init repo if it does not exist
if ([ -z "$(restic cat config)" ]) 2>/dev/null; then
restic {{ restic_archiver__default_opt }} init --copy-chunker-params
fi
# ARCHIVE Settings for Server "{{ repo['name'] | string }}"
export RESTIC_REPOSITORY2="{{ repo['archive_location'] }}"
export RESTIC_PASSWORD2='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
@ -125,13 +176,35 @@ BACKUP_NAME="{{ repo.name }}_archive"
restic {{ restic_archiver__default_opt }} forget {{ retention_pattern(repo) }}
{% endif %}
restic {{ restic_archiver__default_opt }} check
{% if restic_archiver__mail_report | default(false) %}
restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>external_archive</td>\n<td>', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB</td>\n<td> ', str(jsondata['total_file_count']), ' Files.</td>\n</tr>\n')" >> /tmp/mailcontent
{% endif %}
echo -e "</table>\n<br/><br/>" >> /tmp/mailcontent
restic {{ restic_archiver__default_opt }} check --quiet >> /tmp/mailcontent
{% else %}
restic {{ restic_archiver__default_opt }} check
{% endif %}
{% endfor %}
sync
set +euxo pipefail
cat <<EOT >> /tmp/mailcontent
<br/><br/><br/>
<br/><br/><br/>
<br/><br/><br/>
<code>
<pre>
$(df -h)
</pre>
</code>
</body>
</html>
EOT
mail -a "Content-type: text/html" -s "restic backup report" {{ restic_archiver__mailaddress }} < /tmp/mailcontent
{% if restic_archiver__umount_after_usage %}
umount {{ restic_archiver__mount_disk }}
{% endif %}

View file

@ -1,102 +0,0 @@
#!/usr/bin/env bash
# {{ ansible_managed }}
# This file is designed to create a overview
# overof the restic backup and
# send it by mail - if wanted
cat <<EOT > /tmp/mailcontent
<!DOCTYPE html>
<html>
<head>
<title>Restic summary</title>
</head>
<body>
<h1>SUMMARY for Restic BACKUP</h1>
{{ restic_archiver__additional_mail_msg | default ('') }}
EOT
{% for repo in restic_archiver__repos %}
# Settings for Server {{ repo['name'] | string }}
export RESTIC_REPOSITORY="{{ repo['location'] }}" 2>/dev/null
export RESTIC_PASSWORD='{{ repo['password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
BACKUP_NAME="{{ repo.name }}" 2>/dev/null
{#
STARTING MAIL OUTPUT
#}
cat <<EOT >> /tmp/mailcontent
<h2>{{ repo.name }}</h2>
$(restic check --quiet 2>/dev/null)
<h4>Latest Snapshots</h4>
<table style="width:100%">
<tr>
<th>Hostname</th>
<th>latest backup</th>
<th>Path</th>
</tr>
$(restic --quiet snapshots --last --json | jq -c '.[]' | while read i; do echo -e "$i" | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>', jsondata['hostname'], '</td>\n<td>', jsondata['time'], '</td>\n<td>', str(jsondata['paths'][0]), '</td>\n</tr>\n')" ; done)
</table>
<table style="width:100%">
<tr>
<th>name</th>
<th>total size</th>
<th>total files</th>
</tr>
<tr>
<td>snapshots</td>
$(restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<td>', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB </td>\n<td>', str(jsondata['total_file_count']), ' Files</td>')")
</tr>
EOT
{% if repo.archive|default(false) %}
{% if restic_archiver__mount_required %}
if mountpoint -q {{ restic_archiver__mount_disk }}
then
echo "{{ restic_archiver__mount_disk }} is mounted"
else
mount -a 2>/dev/null
fi
{% endif %}
# ARCHIVE Settings for Server "{{ repo['name'] | string }}"
echo "EXTERNAL_BACKUP: {{ repo.name }}" 2>/dev/null
export RESTIC_REPOSITORY="{{ repo['archive_location'] }}" 2>/dev/null
export RESTIC_PASSWORD='{{ repo['archive_password'] | regex_replace('\'', '\'\\\'\'') }}' 2>/dev/null
BACKUP_NAME="{{ repo.name }}_archive" 2>/dev/null
restic --quiet stats --json | python3 -c "import sys, json; jsondata=json.load(sys.stdin); print('<tr>\n<td>external archive</td>\n<td>', str(int(jsondata['total_size'] / 1024 / 1024 / 1024 * 1000 )/1000 ), 'GB</td>\n<td> ', str(jsondata['total_file_count']), ' Files.</td>\n</tr>\n')" >> /tmp/mailcontent
{% endif %}
echo -e "</table>\n<br/><br/>" >> /tmp/mailcontent
restic check --quiet >> /tmp/mailcontent
{% endfor %}
sync
cat <<EOT >> /tmp/mailcontent
<br/><br/><br/>
<br/><br/><br/>
<br/><br/><br/>
<code>
<pre>
$(df -h)
</pre>
</code>
</body>
</html>
EOT
mail -a "Content-type: text/html" -s "restic backup report" {{ restic_archiver__mailaddress }} < /tmp/mailcontent
{% if restic_archiver__umount_after_usage %}
umount {{ restic_archiver__mount_disk }}
{% endif %}

View file

@ -1,3 +1,3 @@
---
playbook_version_number: 38 # should be over ninethousand
playbook_version_number: 40 # should be int
playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version'