Author SHA1 Message Date
alessandrovitali be8ad25a78 fix: arch discovery
refactor repository steps following official docker installation steps
2026-08-04 19:49:02 +02:00
alessandrovitali c7f19cd3b0 fix: simplify host arch discovery 2026-08-04 19:30:37 +02:00
alessandrovitali d1758b692e refactor: docker role 2026-08-04 19:26:33 +02:00
alessandrovitali 16e403a439 fix: use correct ssh daemon for debian 2026-07-23 17:45:06 +02:00
alessandrovitali d4587423a1 fix: galaxy.yml 2026-07-23 16:20:01 +02:00
alessandrovitali 9fbba9ffd6 fix: remove OS checks
either use the generic package module or OS-specific tasks that won't silently fail playbook runs
2026-07-09 16:17:30 +02:00
12 changed files with 59 additions and 141 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
# Ansible Collection
Opinionated set of roles to configure reasonable defaults for newly provisioned Debian / Ubuntu VMs running Docker. The repository provides a ready-to-use Ansible Collection (`studio.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.
+3 -2
View File
@@ -3,8 +3,9 @@
namespace: studio
name: ansible
readme: README.md
version: 1.0.0
version: 0.0.1
authors:
- Studio Vitali
description: Studio Ansible collection containing common roles
license: MIT
license:
- MIT
-14
View File
@@ -1,14 +0,0 @@
# 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
-61
View File
@@ -1,61 +0,0 @@
---
- name: Install restic
ansible.builtin.apt:
name: restic
state: present
- 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 already initialized
ansible.builtin.command: restic snapshots
register: restic_check
failed_when: false
changed_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
@@ -1,5 +0,0 @@
# 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 }}"
@@ -1,8 +0,0 @@
[Unit]
Description=Run Restic Backup
After=network-online.target
[Service]
Type=oneshot
EnvironmentFile=/etc/restic-backup.env
ExecStart=/usr/local/bin/restic-backup.sh
@@ -1,30 +0,0 @@
#!/bin/bash
## Ansible managed
set -e
# 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)"
## 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)"
@@ -1,10 +0,0 @@
[Unit]
Description=Run Restic Backup
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
RandomizedDelaySec=1800
[Install]
WantedBy=timers.target
-2
View File
@@ -10,7 +10,6 @@
update_cache: true
upgrade: dist
cache_valid_time: 3600
when: ansible_facts['os_family'] == "Debian" ## only on Debian / Ubuntu systems
become: true
- name: Install essential system utilities
@@ -26,7 +25,6 @@
- unattended-upgrades
state: present
update_cache: true
when: ansible_facts['os_family'] == "Debian"
become: true
#
# - name: Enable unattended-upgrades
+52 -5
View File
@@ -1,18 +1,58 @@
---
- name: Install necessary Docker packages
- name: Install Docker prerequisites
ansible.builtin.apt:
name:
- docker.io
- docker-compose
- ca-certificates
- curl
state: present
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu
update_cache: true
become: true
- name: Ensure Docker service is running
- name: Ensure APT keyrings directory exists
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
mode: "0755"
become: true
- name: Download Docker official GPG key
ansible.builtin.get_url:
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
dest: /etc/apt/keyrings/docker.asc
mode: "0644"
become: true
- name: Get system architecture
ansible.builtin.command: dpkg --print-architecture
register: dpkg_architecture
changed_when: false
become: true
- name: Add Docker official APT repository
ansible.builtin.apt_repository:
repo: "deb [arch={{ dpkg_architecture.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
state: present
filename: docker
update_cache: yes
become: true
- name: Install modern Docker CE packages
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
become: true
- name: Ensure Docker services are running and enabled
ansible.builtin.service:
name: docker
state: started
enabled: true
become: true
- name: Create docker user for container execution
ansible.builtin.user:
@@ -25,6 +65,13 @@
create_home: false
become: true
- name: Add deployment user to docker group
ansible.builtin.user:
name: deployment
groups: docker
append: true
become: true
- name: Create target for docker compose
ansible.builtin.file:
path: /opt/docker
+1 -1
View File
@@ -1,5 +1,5 @@
---
- name: Restart sshd
ansible.builtin.service:
name: sshd
name: ssh
state: restarted
-2
View File
@@ -24,7 +24,6 @@
name:
- fail2ban
state: present
when: ansible_facts['os_family'] == "Debian"
become: true
- name: Start fail2ban
@@ -32,4 +31,3 @@
name: fail2ban
state: started
enabled: yes
when: ansible_facts['os_family'] == "Debian"