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
6 changed files with 85 additions and 64 deletions
-3
View File
@@ -9,6 +9,3 @@ authors:
description: Studio Ansible collection containing common roles description: Studio Ansible collection containing common roles
license: license:
- MIT - MIT
dependencies:
"devsec.hardening": ">=9.0.0"
-2
View File
@@ -1,2 +0,0 @@
---
requires_ansible: ">=2.15.0"
+40 -32
View File
@@ -4,23 +4,39 @@
name: name:
- ca-certificates - ca-certificates
- curl - curl
- python3-debian ## needed for the deb822 module
state: present state: present
update_cache: true update_cache: true
become: true become: true
- name: Add Docker official APT repository (DEB822 format) - name: Ensure APT keyrings directory exists
ansible.builtin.deb822_repository: ansible.builtin.file:
name: docker path: /etc/apt/keyrings
types: deb state: directory
uris: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}" mode: "0755"
suites: "{{ ansible_facts['distribution_release'] }}"
components: stable
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
state: present
become: true become: true
- name: Install Docker CE packages - 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: ansible.builtin.apt:
name: name:
- docker-ce - docker-ce
@@ -29,16 +45,26 @@
- docker-buildx-plugin - docker-buildx-plugin
- docker-compose-plugin - docker-compose-plugin
state: present state: present
update_cache: true
become: true become: true
- name: Ensure Docker service is running and enabled - name: Ensure Docker services are running and enabled
ansible.builtin.service: ansible.builtin.service:
name: docker name: docker
state: started state: started
enabled: true enabled: true
become: true become: true
- name: Create docker user for container execution
ansible.builtin.user:
name: docker
state: present
system: true
shell: /usr/sbin/nologin
groups: docker
append: true
create_home: false
become: true
- name: Add deployment user to docker group - name: Add deployment user to docker group
ansible.builtin.user: ansible.builtin.user:
name: deployment name: deployment
@@ -46,7 +72,7 @@
append: true append: true
become: true become: true
- name: Create target for docker compose files - name: Create target for docker compose
ansible.builtin.file: ansible.builtin.file:
path: /opt/docker path: /opt/docker
state: directory state: directory
@@ -54,21 +80,3 @@
group: deployment group: deployment
mode: "0755" mode: "0755"
become: true 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
+19 -6
View File
@@ -1,10 +1,23 @@
--- ---
- name: Harden SSH configuration - name: Create SSH drop-in directory
ansible.builtin.import_role: ansible.builtin.file:
name: devsec.hardening.ssh_hardening path: /etc/ssh/sshd_config.d
vars: state: directory
ssh_permit_root_login: "no" owner: root
ssh_password_authentication: "no" 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 - name: Install fail2ban
ansible.builtin.apt: ansible.builtin.apt:
+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 # - name: Create primary admin user
ansible.builtin.user: # ansible.builtin.user:
name: "{{ sysadmin_user }}" # name: sysadmin
groups: sudo # groups: sudo
append: yes # append: yes
shell: /bin/bash # shell: /bin/bash
create_home: yes # create_home: yes
become: true # become: true
- name: Add SSH public key for sysadmin # - name: Add SSH public key for sysadmin
ansible.posix.authorized_key: # ansible.posix.authorized_key:
user: "{{ sysadmin_user }}" # user: sysadmin
state: present # state: present
key: "{{ sysadmin_public_ssh_key }}" # key: "{{ sysadmin_public_ssh_key }}"
become: true # become: true
- name: Allow passwordless sudo for sudo group # - name: Allow passwordless sudo to sysadmin user
ansible.builtin.copy: # ansible.builtin.copy:
dest: /etc/sudoers.d/sudo-nopasswd # dest: /etc/sudoers.d/sysadmin
content: "%sudo ALL=(ALL) NOPASSWD: ALL" # content: "sysadmin ALL=(ALL) NOPASSWD: ALL"
mode: "0440" # mode: "0440"
validate: /usr/sbin/visudo -cf %s # validate: /usr/sbin/visudo -cf %s
become: true # become: true
- name: Create deployment user for CI/CD - name: Create deployment user for CI/CD
ansible.builtin.user: ansible.builtin.user: