1 Commits
Author SHA1 Message Date
alessandrovitali 5b22e7e784 Merge branch 'main' into feat/backup 2026-09-03 16:30:08 +02:00
4 changed files with 50 additions and 54 deletions

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
# Ansible Collection # Ansible Collection
Opinionated set of roles to configure reasonable defaults for newly provisioned virtual machines. The repository provides a ready-to-use Ansible Collection (`studiovitali.ansible`) containing reusable roles. Opinionated set of roles to configure reasonable defaults for newly provisioned virtual machines. The repository provides a ready-to-use Ansible Collection (`studio.ansible`) containing reusable roles.
Currently only supports Debian-based systems. Currently only supports Debian-based systems.
+1 -1
View File
@@ -1,6 +1,6 @@
## galaxy.yml ## galaxy.yml
namespace: studiovitali namespace: studio
name: ansible name: ansible
readme: README.md readme: README.md
version: 0.0.1 version: 0.0.1
+43 -51
View File
@@ -1,69 +1,61 @@
--- ---
- name: Install and initialize restic - name: Install restic
become: true ansible.builtin.apt:
name: restic
state: present
- name: Initialize restic repository
environment: environment:
RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}" RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}"
RESTIC_PASSWORD: "{{ vault_restic_password }}" RESTIC_PASSWORD: "{{ vault_restic_password }}"
AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}" AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}"
AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}" AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}"
block: block:
- name: Install restic - name: Check if already initialized
ansible.builtin.apt: ansible.builtin.command: restic snapshots
name: restic
state: present
update_cache: true
- name: Check if repository is initialized
ansible.builtin.command: restic cat config
register: restic_check register: restic_check
changed_when: false
failed_when: false failed_when: false
changed_when: false
- name: Initialize repository - name: Initialize repository
ansible.builtin.command: restic init ansible.builtin.command: restic init
when: restic_check.rc != 0 when: restic_check.rc != 0
- name: Configure restic backup job - name: Deploy restic environment file
become: true ansible.builtin.template:
block: src: restic-backup.env.j2
- name: Deploy restic environment file dest: /etc/restic-backup.env
ansible.builtin.template: owner: root
src: restic-backup.env.j2 group: root
dest: /etc/restic-backup.env mode: "0600" ## only root can read this file
owner: root
group: root
mode: "0600" ## only root can read this file
- name: Deploy restic backup script - name: Deploy restic backup script
ansible.builtin.template: ansible.builtin.template:
src: restic-backup.sh.j2 src: restic-backup.sh.j2
dest: /usr/local/bin/restic-backup.sh dest: /usr/local/bin/restic-backup.sh
owner: root owner: root
group: root group: root
mode: "0700" ## only root can execute the script mode: "0700" ## only root can execute the script
- name: Schedule restic backups - name: Deploy restic systemd service
become: true ansible.builtin.template:
block: src: restic-backup.service.j2
- name: Deploy restic systemd service dest: /etc/systemd/system/restic-backup.service
ansible.builtin.template: owner: root
src: restic-backup.service.j2 group: root
dest: /etc/systemd/system/restic-backup.service mode: "0644"
owner: root
group: root
mode: "0644"
- name: Deploy restic systemd timer - name: Deploy restic systemd timer
ansible.builtin.template: ansible.builtin.template:
src: restic-backup.timer.j2 src: restic-backup.timer.j2
dest: /etc/systemd/system/restic-backup.timer dest: /etc/systemd/system/restic-backup.timer
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
- name: Enable and start backup timer - name: Enable and start backup timer
ansible.builtin.systemd: ansible.builtin.systemd:
name: restic-backup.timer name: restic-backup.timer
enabled: yes enabled: yes
state: started state: started
daemon_reload: yes daemon_reload: yes
+5 -1
View File
@@ -3,7 +3,11 @@
set -e set -e
## Environment is injected by the systemd unit via EnvironmentFile=/etc/restic-backup.env. Run manually with: systemctl start restic-backup.service # Source environment variables if running manually/outside Systemd
if [ -f /etc/restic-backup.env ]; then
# shellcheck source=/dev/null
. /etc/restic-backup.env
fi
echo "Starting Restic Backup at $(date)" echo "Starting Restic Backup at $(date)"