Author SHA1 Message Date
alessandrovitali ce9b5d58b4 feat: add standalone playbook 2026-06-17 14:09:19 +02:00
alessandrovitali 2c29ea2780 initial commit 2026-06-17 14:09:10 +02:00
11 changed files with 83 additions and 90 deletions
+3 -3
View File
@@ -1,5 +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 (`studio.ansible`) containing reusable roles.
Currently only supports Debian-based systems.
Opinionated set of roles to configure reasonable defaults for newly provisioned Debian / Ubuntu VMs running Docker. The repository provides:
- An Ansible Collection (`studio.ansible`) containing reusable roles. Use with ansible-galaxy's `requirements.yml`.
- A ready-to-use playbook configured by passing CLI vars `--extra-vars "ansible_host=${HOST_IP}` e.g. through CI / CD.
+2 -6
View File
@@ -3,12 +3,8 @@
namespace: studio
name: ansible
readme: README.md
version: 0.0.1
version: 1.0.0
authors:
- Studio Vitali
description: Studio Ansible collection containing common roles
license:
- MIT
dependencies:
"devsec.hardening": ">=9.0.0"
license: MIT
+5
View File
@@ -0,0 +1,5 @@
[target]
target_host ansible_host="{{ ansible_host }}"
[all:vars]
ansible_user="{{ ansible_user }}"
-2
View File
@@ -1,2 +0,0 @@
---
requires_ansible: ">=2.15.0"
+11
View File
@@ -0,0 +1,11 @@
---
- name: Setup machines
hosts: all
become: true
roles:
- base
- users
- security
- docker
# - backup
+2
View File
@@ -10,6 +10,7 @@
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
@@ -25,6 +26,7 @@
- unattended-upgrades
state: present
update_cache: true
when: ansible_facts['os_family'] == "Debian"
become: true
#
# - name: Enable unattended-upgrades
+12 -51
View File
@@ -1,52 +1,31 @@
---
- name: Install Docker prerequisites
- name: Install necessary Docker packages
ansible.builtin.apt:
name:
- ca-certificates
- curl
- python3-debian ## needed for the deb822 module
- docker.io
- docker-compose
state: present
update_cache: true
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu
become: true
- 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
become: true
- 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
become: true
- name: Ensure Docker service is running and enabled
- name: Ensure Docker service is running
ansible.builtin.service:
name: docker
state: started
enabled: true
become: true
- name: Add deployment user to docker group
- name: Create docker user for container execution
ansible.builtin.user:
name: deployment
name: docker
state: present
system: true
shell: /usr/sbin/nologin
groups: docker
append: true
create_home: false
become: true
- name: Create target for docker compose files
- name: Create target for docker compose
ansible.builtin.file:
path: /opt/docker
state: directory
@@ -54,21 +33,3 @@
group: deployment
mode: "0755"
become: true
- name: Create appuser group
ansible.builtin.group:
name: appuser
state: present
gid: 9999
become: true
- name: Create app user for secure container execution
ansible.builtin.user:
name: appuser
state: present
uid: 9999
group: appuser
system: true
shell: /usr/sbin/nologin
create_home: false
become: true
+1 -1
View File
@@ -1,5 +1,5 @@
---
- name: Restart sshd
ansible.builtin.service:
name: ssh
name: sshd
state: restarted
+21 -6
View File
@@ -1,16 +1,30 @@
---
- name: Harden SSH configuration
ansible.builtin.import_role:
name: devsec.hardening.ssh_hardening
vars:
ssh_permit_root_login: "no"
ssh_password_authentication: "no"
- name: Create SSH drop-in directory
ansible.builtin.file:
path: /etc/ssh/sshd_config.d
state: directory
owner: root
group: root
mode: "0755"
become: true
- name: Harden SSH configuration with drop-in template
ansible.builtin.template:
src: sshd.conf.j2
dest: /etc/ssh/sshd_config.d/sshd.conf
owner: root
group: root
mode: "0644"
validate: "sshd -t -f %s"
notify: Restart sshd
become: true
- name: Install fail2ban
ansible.builtin.apt:
name:
- fail2ban
state: present
when: ansible_facts['os_family'] == "Debian"
become: true
- name: Start fail2ban
@@ -18,3 +32,4 @@
name: fail2ban
state: started
enabled: yes
when: ansible_facts['os_family'] == "Debian"
+5
View File
@@ -0,0 +1,5 @@
## Disable root login
PermitRootLogin no
## Disable password authentication
PasswordAuthentication no
+21 -21
View File
@@ -1,27 +1,27 @@
---
- name: Create primary sysadmin user
ansible.builtin.user:
name: "{{ sysadmin_user }}"
groups: sudo
append: yes
shell: /bin/bash
create_home: yes
become: true
# - name: Create primary admin user
# ansible.builtin.user:
# name: sysadmin
# groups: sudo
# append: yes
# shell: /bin/bash
# create_home: yes
# become: true
- name: Add SSH public key for sysadmin
ansible.posix.authorized_key:
user: "{{ sysadmin_user }}"
state: present
key: "{{ sysadmin_public_ssh_key }}"
become: true
# - name: Add SSH public key for sysadmin
# ansible.posix.authorized_key:
# user: sysadmin
# state: present
# key: "{{ sysadmin_public_ssh_key }}"
# become: true
- name: Allow passwordless sudo for sudo group
ansible.builtin.copy:
dest: /etc/sudoers.d/sudo-nopasswd
content: "%sudo ALL=(ALL) NOPASSWD: ALL"
mode: "0440"
validate: /usr/sbin/visudo -cf %s
become: true
# - 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: Create deployment user for CI/CD
ansible.builtin.user: