Compare commits
6
Commits
main
..
c362460b86
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c362460b86 | ||
|
|
39231dce9d | ||
|
|
617883a9a7 | ||
|
|
71a02e0f86 | ||
|
|
c4c8d6de7f | ||
|
|
8d96529d8f |
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
# 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 (`studiovitali.ansible`) containing reusable roles.
|
||||||
|
|
||||||
Currently only supports Debian-based systems.
|
Currently only supports Debian-based systems.
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
namespace: studiovitali
|
namespace: studiovitali
|
||||||
name: ansible
|
name: ansible
|
||||||
readme: README.md
|
readme: README.md
|
||||||
version: 0.1.1
|
version: 0.0.1
|
||||||
authors:
|
authors:
|
||||||
- Studio Vitali
|
- Studio Vitali
|
||||||
description: Studio Ansible collection containing common roles
|
description: Studio Ansible collection containing common roles
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# ansible/roles/backup/defaults/main.yml
|
||||||
|
---
|
||||||
|
## Directories to include in the backup
|
||||||
|
backup_include_paths:
|
||||||
|
- /etc
|
||||||
|
- /opt/docker
|
||||||
|
|
||||||
|
## Directories to exclude from the backup
|
||||||
|
backup_exclude_paths: [] ## Nothing to exclude
|
||||||
|
|
||||||
|
## Restic retention policy
|
||||||
|
backup_retention_daily: 7
|
||||||
|
backup_retention_weekly: 4
|
||||||
|
backup_retention_monthly: 6
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
---
|
||||||
|
- name: Install restic
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: restic
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
|
||||||
|
- name: Initialize restic repository
|
||||||
|
environment:
|
||||||
|
RESTIC_REPOSITORY: "{{ vault_restic_repo_url }}"
|
||||||
|
RESTIC_PASSWORD: "{{ vault_restic_password }}"
|
||||||
|
AWS_ACCESS_KEY_ID: "{{ vault_aws_access_key }}"
|
||||||
|
AWS_SECRET_ACCESS_KEY: "{{ vault_aws_secret_key }}"
|
||||||
|
block:
|
||||||
|
- name: Check if repository is initialized
|
||||||
|
command: restic cat config
|
||||||
|
register: restic_check
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Initialize repository
|
||||||
|
ansible.builtin.command: restic init
|
||||||
|
when: restic_check.rc != 0
|
||||||
|
|
||||||
|
- name: Deploy restic environment file
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: restic-backup.env.j2
|
||||||
|
dest: /etc/restic-backup.env
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600" ## only root can read this file
|
||||||
|
|
||||||
|
- name: Deploy restic backup script
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: restic-backup.sh.j2
|
||||||
|
dest: /usr/local/bin/restic-backup.sh
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0700" ## only root can execute the script
|
||||||
|
|
||||||
|
- name: Deploy restic systemd service
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: restic-backup.service.j2
|
||||||
|
dest: /etc/systemd/system/restic-backup.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Deploy restic systemd timer
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: restic-backup.timer.j2
|
||||||
|
dest: /etc/systemd/system/restic-backup.timer
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Enable and start backup timer
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: restic-backup.timer
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
daemon_reload: yes
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Ansible managed
|
||||||
|
RESTIC_REPOSITORY="{{ vault_restic_repo_url }}"
|
||||||
|
RESTIC_PASSWORD="{{ vault_restic_password }}"
|
||||||
|
AWS_ACCESS_KEY_ID="{{ vault_aws_access_key }}"
|
||||||
|
AWS_SECRET_ACCESS_KEY="{{ vault_aws_secret_key }}"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run Restic Backup
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
EnvironmentFile=/etc/restic-backup.env
|
||||||
|
ExecStart=/usr/local/bin/restic-backup.sh
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
## Ansible managed
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
## Environment is injected by the systemd unit via EnvironmentFile=/etc/restic-backup.env. Run manually with: systemctl start restic-backup.service
|
||||||
|
|
||||||
|
echo "Starting Restic Backup at $(date)"
|
||||||
|
|
||||||
|
## Run the backup using paths and exclusions defined as group_vars
|
||||||
|
restic backup \
|
||||||
|
{% for path in backup_include_paths %}
|
||||||
|
"{{ path }}" \
|
||||||
|
{% endfor %}
|
||||||
|
{% for path in backup_exclude_paths %}
|
||||||
|
--exclude "{{ path }}" \
|
||||||
|
{% endfor %}
|
||||||
|
--cleanup-cache
|
||||||
|
|
||||||
|
restic forget \
|
||||||
|
--prune \
|
||||||
|
--keep-daily {{ backup_retention_daily }} \
|
||||||
|
--keep-weekly {{ backup_retention_weekly }} \
|
||||||
|
--keep-monthly {{ backup_retention_monthly }}
|
||||||
|
|
||||||
|
echo "Restic backup completed at $(date)"
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run Restic Backup
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 04:00:00
|
||||||
|
Persistent=true
|
||||||
|
RandomizedDelaySec=1800
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
@@ -9,6 +9,6 @@ base_packages:
|
|||||||
- rsync
|
- rsync
|
||||||
- unzip
|
- unzip
|
||||||
- unattended-upgrades
|
- unattended-upgrades
|
||||||
# - acl ## needed for ansible to become unprivileged user
|
# - acl ## needed for Ansible to become unprivileged user
|
||||||
# - python3-pip
|
# - python3-pip
|
||||||
# - wget
|
# - wget
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Reboot system
|
|
||||||
block:
|
|
||||||
- name: Check if reboot is required
|
|
||||||
ansible.builtin.stat:
|
|
||||||
path: /var/run/reboot-required
|
|
||||||
register: reboot_required_file
|
|
||||||
|
|
||||||
- name: Reboot host if necessary
|
|
||||||
become: true
|
|
||||||
ansible.builtin.reboot:
|
|
||||||
post_reboot_delay: 10
|
|
||||||
when: reboot_required_file.stat.exists
|
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: Set system timezone
|
- name: Set system timezone
|
||||||
become: true
|
|
||||||
community.general.timezone:
|
community.general.timezone:
|
||||||
# name: "{{ base_timezone }}"
|
# name: "{{ base_timezone }}"
|
||||||
name: Europe/Zurich
|
name: Europe/Zurich
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Fully upgrade system
|
- name: Fully upgrade system
|
||||||
become: true
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
notify: Reboot system
|
become: true
|
||||||
|
|
||||||
- name: Install essential system utilities
|
- name: Install essential system utilities
|
||||||
become: true
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
# name: "{{ base_packages }}"
|
# name: "{{ base_packages }}"
|
||||||
name:
|
name:
|
||||||
@@ -27,7 +25,8 @@
|
|||||||
- unattended-upgrades
|
- unattended-upgrades
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
#
|
||||||
# - name: Enable unattended-upgrades
|
# - name: Enable unattended-upgrades
|
||||||
# ansible.builtin.copy:
|
# ansible.builtin.copy:
|
||||||
# dest: /etc/apt/apt.conf.d/20auto-upgrades
|
# dest: /etc/apt/apt.conf.d/20auto-upgrades
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Restart sshd
|
- name: Restart sshd
|
||||||
become: true
|
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: ssh
|
name: ssh
|
||||||
state: restarted
|
state: restarted
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
validate: /usr/sbin/sshd -t -f %s
|
|
||||||
notify: Restart sshd
|
notify: Restart sshd
|
||||||
|
|
||||||
- name: Enable fail2ban
|
- name: Enable fail2ban
|
||||||
@@ -33,4 +32,4 @@
|
|||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: fail2ban
|
name: fail2ban
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: yes
|
||||||
Reference in new issue
Block a user