Author SHA1 Message Date
alessandrovitali 63b5d37883 fix: directory traversal permission 2026-08-19 19:50:22 +02:00
alessandrovitali 5308e5312d Merge branch 'main' into feat/coolify 2026-08-19 19:43:33 +02:00
alessandrovitali cba507b077 fix: user creation 2026-08-19 19:42:55 +02:00
alessandrovitali 4fdab81b9c feat: pre-seed admin user 2026-08-18 17:52:12 +02:00
alessandrovitali 472f04b98c feat: add coolify installation role 2026-08-17 17:52:01 +02:00
alessandrovitali 0974c13751 chore: add conditional to user configuration 2026-08-17 17:43:05 +02:00
alessandrovitali 6e4bd8eb92 feat: group tasks into logical blocks 2026-08-17 14:18:24 +02:00
alessandrovitali d1714e0fa4 feat: add conditionals to user creation 2026-08-17 00:08:39 +02:00
alessandrovitali 80a1ca0632 chore 2026-08-17 00:05:30 +02:00
alessandrovitali b031c08b66 fix: SSH config validation
remove validation step instead of running pointless validation on static template
2026-08-06 12:39:58 +02:00
alessandrovitali 1370cd2b8a refactor: user creation (#7)
parameterize sysadmin username
2026-08-05 16:24:11 +02:00
alessandrovitali 7c9d7050e9 fix: refresh apt cache before installing docker packages 2026-08-05 00:29:12 +02:00
alessandrovitali bdd1c07d76 refactor: use modern deb822 repository module 2026-08-04 22:12:05 +02:00
alessandrovitali f59952df2b fix: update outdated ansible_facts notation 2026-08-04 21:59:47 +02:00
alessandrovitali f9e26303d0 fix: docker container execution user permissions
do not add appuser to docker group (highly insecure) / hardcode GID:UID
2026-08-04 20:30:17 +02:00
alessandrovitali b6d861a8d4 fix: add runtime.yml with minimum supported ansible version 2026-08-04 20:03:01 +02:00
alessandrovitali ff9d9adc96 fix: arch discovery
refactor repository steps following official docker installation steps
2026-08-04 19:53:51 +02:00
alessandrovitali 960379bd16 refactor: docker role (#6)
use official docker images instead of outdated apt packages following official docker installation docs
2026-08-04 19:34:56 +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
16 changed files with 192 additions and 228 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
# Ansible Collection # 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 namespace: studio
name: ansible name: ansible
readme: README.md readme: README.md
version: 1.0.0 version: 0.0.1
authors: authors:
- Studio Vitali - Studio Vitali
description: Studio Ansible collection containing common roles description: Studio Ansible collection containing common roles
license: MIT license:
- MIT
+2
View File
@@ -0,0 +1,2 @@
---
requires_ansible: ">=2.15.0"
-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
-4
View File
@@ -10,7 +10,6 @@
update_cache: true update_cache: true
upgrade: dist upgrade: dist
cache_valid_time: 3600 cache_valid_time: 3600
when: ansible_facts['os_family'] == "Debian" ## only on Debian / Ubuntu systems
become: true become: true
- name: Install essential system utilities - name: Install essential system utilities
@@ -26,7 +25,6 @@
- unattended-upgrades - unattended-upgrades
state: present state: present
update_cache: true update_cache: true
when: ansible_facts['os_family'] == "Debian"
become: true become: true
# #
# - name: Enable unattended-upgrades # - name: Enable unattended-upgrades
@@ -37,5 +35,3 @@
# APT::Periodic::Unattended-Upgrade "1"; # APT::Periodic::Unattended-Upgrade "1";
# mode: "0644" # mode: "0644"
# when: ansible_facts['os_family'] == "Debian" # when: ansible_facts['os_family'] == "Debian"
## SCHEDULE REBOOTS 4 kernel upgrades: with cron, unattended-upgrades or action workflows?
+16
View File
@@ -0,0 +1,16 @@
---
coolify_installer_url: "https://cdn.coollabs.io/coolify/install.sh"
coolify_installer_dest: "/tmp/coolify-install.sh"
coolify_data_dir: "/data/coolify"
coolify_compose_file: "{{ coolify_data_dir }}/source/docker-compose.yml"
## Pin to a release or leave empty for latest
coolify_version: ""
## Set to false to manage upgrades manually
coolify_autoupdate: true
## All 3 needed for sucessful user creation
coolify_root_username: ""
coolify_root_user_email: ""
coolify_root_user_password: ""
+30
View File
@@ -0,0 +1,30 @@
---
- name: Check if Coolify is already installed
become: true
ansible.builtin.stat:
path: "{{ coolify_compose_file }}"
register: coolify_installed
- name: Download Coolify installer
ansible.builtin.get_url:
url: "{{ coolify_installer_url }}"
dest: "{{ coolify_installer_dest }}"
mode: "0755"
when: not coolify_installed.stat.exists
- name: Run Coolify installer
become: true
ansible.builtin.command:
argv:
- "{{ coolify_installer_dest }}"
- "{{ coolify_version }}"
environment:
AUTOUPDATE: "{{ coolify_autoupdate | bool | ternary('true', 'false') }}"
ROOT_USERNAME: "{{ coolify_root_username }}"
ROOT_USER_EMAIL: "{{ coolify_root_user_email }}"
ROOT_USER_PASSWORD: "{{ coolify_root_user_password }}"
when: not coolify_installed.stat.exists
changed_when: true
async: 1800
poll: 15
no_log: true
+54 -13
View File
@@ -1,29 +1,52 @@
--- ---
- name: Install necessary Docker packages - name: Install Docker
become: true
block:
- name: Install Docker prerequisites
ansible.builtin.apt: ansible.builtin.apt:
name: name:
- docker.io - ca-certificates
- docker-compose - curl
- python3-debian ## needed for the deb822 module
state: present state: present
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu update_cache: true
become: true
- name: Ensure Docker service is running - name: Add Docker official APT repository (DEB822 format)
ansible.builtin.deb822_repository:
name: docker
types: deb
uris: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}"
suites: "{{ ansible_facts['distribution_release'] }}"
components: stable
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
state: present
- name: Install Docker CE packages
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: true
- name: Ensure Docker service is running and enabled
ansible.builtin.service: ansible.builtin.service:
name: docker name: docker
state: started state: started
enabled: true enabled: true
- name: Create docker user for container execution - name: Configure deployment user for Docker
when: deployment_public_ssh_key is defined
become: true
block:
- name: Add deployment user to docker group
ansible.builtin.user: ansible.builtin.user:
name: docker name: deployment
state: present
system: true
shell: /usr/sbin/nologin
groups: docker groups: docker
append: true append: true
create_home: false
become: true
- name: Create target for docker compose - name: Create target for docker compose
ansible.builtin.file: ansible.builtin.file:
@@ -32,4 +55,22 @@
owner: deployment owner: deployment
group: deployment group: deployment
mode: "0755" mode: "0755"
- name: Create app user for secure container execution
become: true become: true
block:
- name: Create appuser group
ansible.builtin.group:
name: appuser
state: present
gid: 9999
- name: Create appuser
ansible.builtin.user:
name: appuser
state: present
uid: 9999
group: appuser
system: true
shell: /usr/sbin/nologin
create_home: false
+1 -1
View File
@@ -1,5 +1,5 @@
--- ---
- name: Restart sshd - name: Restart sshd
ansible.builtin.service: ansible.builtin.service:
name: sshd name: ssh
state: restarted state: restarted
+6 -6
View File
@@ -1,4 +1,7 @@
--- ---
- name: Harden SSH configuration
become: true
block:
- name: Create SSH drop-in directory - name: Create SSH drop-in directory
ansible.builtin.file: ansible.builtin.file:
path: /etc/ssh/sshd_config.d path: /etc/ssh/sshd_config.d
@@ -6,7 +9,6 @@
owner: root owner: root
group: root group: root
mode: "0755" mode: "0755"
become: true
- name: Harden SSH configuration with drop-in template - name: Harden SSH configuration with drop-in template
ansible.builtin.template: ansible.builtin.template:
@@ -15,21 +17,19 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
validate: "sshd -t -f %s"
notify: Restart sshd notify: Restart sshd
become: true
- name: Enable fail2ban
become: true
block:
- name: Install fail2ban - name: Install fail2ban
ansible.builtin.apt: ansible.builtin.apt:
name: name:
- fail2ban - fail2ban
state: present state: present
when: ansible_facts['os_family'] == "Debian"
become: true
- name: Start fail2ban - name: Start fail2ban
ansible.builtin.service: ansible.builtin.service:
name: fail2ban name: fail2ban
state: started state: started
enabled: yes enabled: yes
when: ansible_facts['os_family'] == "Debian"
+29 -25
View File
@@ -1,38 +1,42 @@
--- ---
# - name: Create primary admin user - name: Set up primary sysadmin user
# ansible.builtin.user: when: sysadmin_public_ssh_key is defined
# name: sysadmin become: true
# groups: sudo block:
# append: yes - name: Create sysadmin user
# shell: /bin/bash ansible.builtin.user:
# create_home: yes name: "{{ sysadmin_user }}"
# become: true groups: sudo
append: yes
shell: /bin/bash
create_home: yes
# - name: Add SSH public key for sysadmin - name: Add SSH public key
# ansible.posix.authorized_key: ansible.posix.authorized_key:
# user: sysadmin user: "{{ sysadmin_user }}"
# state: present state: present
# key: "{{ sysadmin_public_ssh_key }}" key: "{{ sysadmin_public_ssh_key }}"
# become: true
# - name: Allow passwordless sudo to sysadmin user - name: Allow passwordless sudo
# ansible.builtin.copy: ansible.builtin.copy:
# dest: /etc/sudoers.d/sysadmin dest: /etc/sudoers.d/sudo-nopasswd
# content: "sysadmin ALL=(ALL) NOPASSWD: ALL" content: "%sudo ALL=(ALL) NOPASSWD: ALL"
# mode: "0440" mode: "0440"
# validate: /usr/sbin/visudo -cf %s validate: /usr/sbin/visudo -cf %s
# become: true
- name: Create deployment user for CI/CD
- name: Set up deployment user for CI/CD
when: deployment_public_ssh_key is defined
become: true
block:
- name: Create deployment user
ansible.builtin.user: ansible.builtin.user:
name: deployment name: deployment
shell: /bin/bash shell: /bin/bash
create_home: yes create_home: yes
become: true
- name: Add SSH public key for deployment user - name: Add SSH public key
ansible.posix.authorized_key: ansible.posix.authorized_key:
user: deployment user: deployment
state: present state: present
key: "{{ deployment_public_ssh_key }}" key: "{{ deployment_public_ssh_key }}"
become: true