Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63b5d37883 | ||
|
|
5308e5312d | ||
|
|
cba507b077 | ||
|
|
4fdab81b9c | ||
|
|
472f04b98c | ||
|
|
0974c13751 | ||
|
|
6e4bd8eb92 | ||
|
|
d1714e0fa4 | ||
|
|
80a1ca0632 | ||
|
|
b031c08b66 | ||
|
|
1370cd2b8a | ||
|
|
7c9d7050e9 | ||
|
|
bdd1c07d76 | ||
|
|
f59952df2b | ||
|
|
f9e26303d0 | ||
|
|
b6d861a8d4 | ||
|
|
ff9d9adc96 | ||
|
|
960379bd16 | ||
|
|
16e403a439 | ||
|
|
d4587423a1 | ||
|
|
9fbba9ffd6 |
@@ -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
@@ -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
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
requires_ansible: ">=2.15.0"
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -37,5 +35,3 @@
|
||||
# APT::Periodic::Unattended-Upgrade "1";
|
||||
# mode: "0644"
|
||||
# when: ansible_facts['os_family'] == "Debian"
|
||||
|
||||
## SCHEDULE REBOOTS 4 kernel upgrades: with cron, unattended-upgrades or action workflows?
|
||||
|
||||
@@ -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: ""
|
||||
@@ -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
@@ -1,29 +1,52 @@
|
||||
---
|
||||
- name: Install necessary Docker packages
|
||||
- name: Install Docker
|
||||
become: true
|
||||
block:
|
||||
- name: Install Docker prerequisites
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- docker.io
|
||||
- docker-compose
|
||||
- ca-certificates
|
||||
- curl
|
||||
- python3-debian ## needed for the deb822 module
|
||||
state: present
|
||||
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu
|
||||
become: true
|
||||
update_cache: 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:
|
||||
name: docker
|
||||
state: started
|
||||
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:
|
||||
name: docker
|
||||
state: present
|
||||
system: true
|
||||
shell: /usr/sbin/nologin
|
||||
name: deployment
|
||||
groups: docker
|
||||
append: true
|
||||
create_home: false
|
||||
become: true
|
||||
|
||||
- name: Create target for docker compose
|
||||
ansible.builtin.file:
|
||||
@@ -32,4 +55,22 @@
|
||||
owner: deployment
|
||||
group: deployment
|
||||
mode: "0755"
|
||||
|
||||
- name: Create app user for secure container execution
|
||||
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,5 +1,5 @@
|
||||
---
|
||||
- name: Restart sshd
|
||||
ansible.builtin.service:
|
||||
name: sshd
|
||||
name: ssh
|
||||
state: restarted
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
---
|
||||
- name: Harden SSH configuration
|
||||
become: true
|
||||
block:
|
||||
- name: Create SSH drop-in directory
|
||||
ansible.builtin.file:
|
||||
path: /etc/ssh/sshd_config.d
|
||||
@@ -6,7 +9,6 @@
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
become: true
|
||||
|
||||
- name: Harden SSH configuration with drop-in template
|
||||
ansible.builtin.template:
|
||||
@@ -15,21 +17,19 @@
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
validate: "sshd -t -f %s"
|
||||
notify: Restart sshd
|
||||
become: true
|
||||
|
||||
- name: Enable fail2ban
|
||||
become: true
|
||||
block:
|
||||
- name: Install fail2ban
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- fail2ban
|
||||
state: present
|
||||
when: ansible_facts['os_family'] == "Debian"
|
||||
become: true
|
||||
|
||||
- name: Start fail2ban
|
||||
ansible.builtin.service:
|
||||
name: fail2ban
|
||||
state: started
|
||||
enabled: yes
|
||||
when: ansible_facts['os_family'] == "Debian"
|
||||
|
||||
+29
-25
@@ -1,38 +1,42 @@
|
||||
---
|
||||
# - name: Create primary admin user
|
||||
# ansible.builtin.user:
|
||||
# name: sysadmin
|
||||
# groups: sudo
|
||||
# append: yes
|
||||
# shell: /bin/bash
|
||||
# create_home: yes
|
||||
# become: true
|
||||
- name: Set up primary sysadmin user
|
||||
when: sysadmin_public_ssh_key is defined
|
||||
become: true
|
||||
block:
|
||||
- name: Create sysadmin user
|
||||
ansible.builtin.user:
|
||||
name: "{{ sysadmin_user }}"
|
||||
groups: sudo
|
||||
append: yes
|
||||
shell: /bin/bash
|
||||
create_home: yes
|
||||
|
||||
# - name: Add SSH public key for sysadmin
|
||||
# ansible.posix.authorized_key:
|
||||
# user: sysadmin
|
||||
# state: present
|
||||
# key: "{{ sysadmin_public_ssh_key }}"
|
||||
# become: true
|
||||
- name: Add SSH public key
|
||||
ansible.posix.authorized_key:
|
||||
user: "{{ sysadmin_user }}"
|
||||
state: present
|
||||
key: "{{ sysadmin_public_ssh_key }}"
|
||||
|
||||
# - name: Allow passwordless sudo to sysadmin user
|
||||
# ansible.builtin.copy:
|
||||
# dest: /etc/sudoers.d/sysadmin
|
||||
# content: "sysadmin ALL=(ALL) NOPASSWD: ALL"
|
||||
# mode: "0440"
|
||||
# validate: /usr/sbin/visudo -cf %s
|
||||
# become: true
|
||||
- name: Allow passwordless sudo
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/sudoers.d/sudo-nopasswd
|
||||
content: "%sudo ALL=(ALL) NOPASSWD: ALL"
|
||||
mode: "0440"
|
||||
validate: /usr/sbin/visudo -cf %s
|
||||
|
||||
- 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:
|
||||
name: deployment
|
||||
shell: /bin/bash
|
||||
create_home: yes
|
||||
become: true
|
||||
|
||||
- name: Add SSH public key for deployment user
|
||||
- name: Add SSH public key
|
||||
ansible.posix.authorized_key:
|
||||
user: deployment
|
||||
state: present
|
||||
key: "{{ deployment_public_ssh_key }}"
|
||||
become: true
|
||||
|
||||
Reference in New Issue
Block a user