From 186f2d80eb5114211ecba7d78e56489f5f91e881 Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 7 Dec 2021 17:31:48 +0100 Subject: [PATCH 1/3] update restic cron repo --- tasks/cron.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tasks/cron.yml b/tasks/cron.yml index 956268d..4377296 100644 --- a/tasks/cron.yml +++ b/tasks/cron.yml @@ -5,12 +5,18 @@ name: "{{ restic_archiver__package }}" state: present +- 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 become: true ansible.builtin.cron: name: "archive restic backup with ansible_role_restic_archiver" job: /opt/restic-backup.sh >> /var/log/restic/restic_archiver.log - cron_file: /etc/crontab + cron_file: restic_archiver hour: "{{ restic_archiver__hour }}" minute: "{{ restic_archiver__minute }}" user: "{{ restic_archiver__owner }}" @@ -21,7 +27,7 @@ ansible.builtin.cron: name: "archive restic backup with ansible_role_restic_archiver" job: /opt/restic-backup.sh - cron_file: /etc/crontab + cron_file: restic_archiver hour: "{{ restic_archiver__hour }}" minute: "{{ restic_archiver__minute }}" user: "{{ restic_archiver__owner }}" From e653dc55c22441d0de98e6d46a1a113a77d7597b Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 7 Dec 2021 19:50:02 +0100 Subject: [PATCH 2/3] introducing systemd timer --- defaults/main.yml | 8 ++++++-- handlers/main.yml | 18 ++++++++++++++++++ tasks/main.yml | 6 +++++- tasks/systemd.yml | 24 ++++++++++++++++++++++++ templates/restic-archiver.service.j2 | 11 +++++++++++ templates/restic-archiver.timer.j2 | 10 ++++++++++ vars/main.yml | 2 +- 7 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 handlers/main.yml create mode 100644 tasks/systemd.yml create mode 100644 templates/restic-archiver.service.j2 create mode 100644 templates/restic-archiver.timer.j2 diff --git a/defaults/main.yml b/defaults/main.yml index fc257c0..3a2bb14 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -33,8 +33,10 @@ restic_archiver__owner: 'root' restic_archiver__group: 'root' # shedule restic cronjob -restic_archiver__hour: '3' -restic_archiver__minute: '32' +restic_archiver__hour: '4' +restic_archiver__minute: '23' +restic_archiver__oncalendar: '*-*-* 04:23:00' +restic_archiver__randomizeddelaysec: '900' # validate if disk is mounted restic_archiver__mount_required: false @@ -66,3 +68,5 @@ restic_archiver__cache_config: false restic_archiver__cache_dir: '~/.cache/restic' restic_archiver__prune: false + +restic_archiver__use_systemd_timer: true diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..729a92f --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,18 @@ +--- +- name: systemctl daemon-reload + become: true + ansible.builtin.systemd: + daemon_reload: true + +- name: systemctl start restic-archiver.timer + become: true + ansible.builtin.systemd: + name: restic-archiver.timer + enabled: true + state: started + +- name: systemctl enable restic-archiver.service + become: true + ansible.builtin.systemd: + name: restic-archiver.service + enabled: true diff --git a/tasks/main.yml b/tasks/main.yml index 0cf35ec..ff59204 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,7 +18,11 @@ - name: create cronjob ansible.builtin.include_tasks: cron.yml -# todo: replace with systemd timer + when: not restic_archiver__use_systemd_timer | bool + +- name: create systemd timer + ansible.builtin.include_tasks: systemd.yml + when: restic_archiver__use_systemd_timer | bool - name: install requirements for mailing ansible.builtin.include_tasks: mail.yml diff --git a/tasks/systemd.yml b/tasks/systemd.yml new file mode 100644 index 0000000..16579c9 --- /dev/null +++ b/tasks/systemd.yml @@ -0,0 +1,24 @@ +--- +- name: create restic-archiver.service + become: true + ansible.builtin.template: + src: templates/restic-archiver.service.j2 + dest: /lib/systemd/system/restic-archiver.service + mode: 0644 + owner: root + group: root + notify: + - systemctl daemon-reload + - systemctl enable restic-archiver.service + +- name: create restic-archiver.timer + become: true + ansible.builtin.template: + src: templates/restic-archiver.timer.j2 + dest: /lib/systemd/system/restic-archiver.timer + mode: 0644 + owner: root + group: root + notify: + - systemctl daemon-reload + - systemctl start restic-archiver.timer diff --git a/templates/restic-archiver.service.j2 b/templates/restic-archiver.service.j2 new file mode 100644 index 0000000..66a3d45 --- /dev/null +++ b/templates/restic-archiver.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=restic-archiver +Documentation=https://github.com/roles-ansible/ansible_role_restic_archiver.git + +[Service] +Type=oneshot +ExecStart=/opt/restic-backup.sh +TimeoutStartSec=0 +{% if restic_archiver__log_output -%} +StandardOutput=append:/var/log/restic/restic_archiver.log +{%- endif -%} diff --git a/templates/restic-archiver.timer.j2 b/templates/restic-archiver.timer.j2 new file mode 100644 index 0000000..98b2851 --- /dev/null +++ b/templates/restic-archiver.timer.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=Systemd Timer to run the Restic archiver from /opt/restic-backup.sh + +[Timer] +OnCalendar={{ restic_archiver__oncalendar | default('*-*-* 04:23:00') }} +RandomizedDelaySec={{ restic_archiver__randomizeddelaysec }} +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/vars/main.yml b/vars/main.yml index 8dfef90..f403bcd 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 49 # should be int +playbook_version_number: 50 # should be int playbook_version_path: 'role-restic_archiver_roles-ansible_github.com.version' From a057fcf9769345b55a5819f9be7223a992ef8ef3 Mon Sep 17 00:00:00 2001 From: L3D Date: Wed, 8 Dec 2021 11:20:51 +0100 Subject: [PATCH 3/3] delete checks who do not use systemd stuff --- .github/workflows/ansible-debian-bullseye.yml | 18 ------------------ .github/workflows/ansible-debian-buster.yml | 18 ------------------ .github/workflows/ansible-debian-latest.yml | 18 ------------------ .github/workflows/ansible-debian-sid.yml | 18 ------------------ .github/workflows/ansible-debian-stable.yml | 18 ------------------ .github/workflows/ansible-debian-stretch.yml | 18 ------------------ .github/workflows/ansible-ubuntu-latest.yml | 18 ------------------ .github/workflows/ansible-ubuntu-trusty.yml | 18 ------------------ 8 files changed, 144 deletions(-) delete mode 100644 .github/workflows/ansible-debian-bullseye.yml delete mode 100644 .github/workflows/ansible-debian-buster.yml delete mode 100644 .github/workflows/ansible-debian-latest.yml delete mode 100644 .github/workflows/ansible-debian-sid.yml delete mode 100644 .github/workflows/ansible-debian-stable.yml delete mode 100644 .github/workflows/ansible-debian-stretch.yml delete mode 100644 .github/workflows/ansible-ubuntu-latest.yml delete mode 100644 .github/workflows/ansible-ubuntu-trusty.yml diff --git a/.github/workflows/ansible-debian-bullseye.yml b/.github/workflows/ansible-debian-bullseye.yml deleted file mode 100644 index 4b7c45d..0000000 --- a/.github/workflows/ansible-debian-bullseye.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:bullseye - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: ansible check with debian:bullseye - uses: roles-ansible/check-ansible-debian-bullseye-action@main - with: - targets: "./" diff --git a/.github/workflows/ansible-debian-buster.yml b/.github/workflows/ansible-debian-buster.yml deleted file mode 100644 index 5aca449..0000000 --- a/.github/workflows/ansible-debian-buster.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:buster - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.4 - - - name: ansible check with debian:buster - uses: roles-ansible/check-ansible-debian-buster-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-debian-latest.yml b/.github/workflows/ansible-debian-latest.yml deleted file mode 100644 index f561830..0000000 --- a/.github/workflows/ansible-debian-latest.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:latest - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.4 - - - name: ansible check with debian:latest - uses: roles-ansible/check-ansible-debian-latest-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-debian-sid.yml b/.github/workflows/ansible-debian-sid.yml deleted file mode 100644 index 3ebfd1f..0000000 --- a/.github/workflows/ansible-debian-sid.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:sid - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.4 - - - name: ansible check with debian:sid - uses: roles-ansible/check-ansible-debian-sid-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-debian-stable.yml b/.github/workflows/ansible-debian-stable.yml deleted file mode 100644 index c0076d8..0000000 --- a/.github/workflows/ansible-debian-stable.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:stable - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.4 - - - name: ansible check with debian:stable - uses: roles-ansible/check-ansible-debian-stable-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-debian-stretch.yml b/.github/workflows/ansible-debian-stretch.yml deleted file mode 100644 index 65dccd4..0000000 --- a/.github/workflows/ansible-debian-stretch.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Ansible check debian:stretch - -# yamllint disable-line rule:truthy -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2.3.4 - - - name: ansible check with debian:stretch - uses: roles-ansible/check-ansible-debian-stretch-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-ubuntu-latest.yml b/.github/workflows/ansible-ubuntu-latest.yml deleted file mode 100644 index 763f01e..0000000 --- a/.github/workflows/ansible-ubuntu-latest.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -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.3.4 - - - name: ansible check with ubuntu:latest - uses: roles-ansible/check-ansible-ubuntu-latest-action@master - with: - targets: "./" diff --git a/.github/workflows/ansible-ubuntu-trusty.yml b/.github/workflows/ansible-ubuntu-trusty.yml deleted file mode 100644 index a136f77..0000000 --- a/.github/workflows/ansible-ubuntu-trusty.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -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.3.4 - - - name: ansible check with ubuntu:trusty - uses: roles-ansible/check-ansible-ubuntu-trusty-action@master - with: - targets: "./"