Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf66355832 |
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
Opinionated set of roles to configure reasonable defaults for newly provisioned virtual machines. The repository provides a ready-to-use Ansible Collection (`studiovitali.ansible`) containing reusable roles.
|
# 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.
|
Currently only supports Debian-based systems.
|
||||||
+5
-2
@@ -1,11 +1,14 @@
|
|||||||
## galaxy.yml
|
## galaxy.yml
|
||||||
|
|
||||||
namespace: studiovitali
|
namespace: studio
|
||||||
name: ansible
|
name: ansible
|
||||||
readme: README.md
|
readme: README.md
|
||||||
version: 0.1.1
|
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:
|
license:
|
||||||
- MIT
|
- MIT
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
"devsec.hardening": ">=9.0.0"
|
||||||
@@ -9,6 +9,6 @@ base_packages:
|
|||||||
- rsync
|
- rsync
|
||||||
- unzip
|
- unzip
|
||||||
- unattended-upgrades
|
- unattended-upgrades
|
||||||
# - acl ## needed for ansible to become unprivileged user
|
# - acl ## needed for Ansible to become unprivileged user
|
||||||
# - python3-pip
|
# - python3-pip
|
||||||
# - wget
|
# - wget
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Reboot system
|
|
||||||
block:
|
|
||||||
- name: Check if reboot is required
|
|
||||||
ansible.builtin.stat:
|
|
||||||
path: /var/run/reboot-required
|
|
||||||
register: reboot_required_file
|
|
||||||
|
|
||||||
- name: Reboot host if necessary
|
|
||||||
become: true
|
|
||||||
ansible.builtin.reboot:
|
|
||||||
post_reboot_delay: 10
|
|
||||||
when: reboot_required_file.stat.exists
|
|
||||||
@@ -1,20 +1,18 @@
|
|||||||
---
|
---
|
||||||
- name: Set system timezone
|
- name: Set system timezone
|
||||||
become: true
|
|
||||||
community.general.timezone:
|
community.general.timezone:
|
||||||
# name: "{{ base_timezone }}"
|
# name: "{{ base_timezone }}"
|
||||||
name: Europe/Zurich
|
name: Europe/Zurich
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Fully upgrade system
|
- name: Fully upgrade system
|
||||||
become: true
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
upgrade: dist
|
upgrade: dist
|
||||||
cache_valid_time: 3600
|
cache_valid_time: 3600
|
||||||
notify: Reboot system
|
become: true
|
||||||
|
|
||||||
- name: Install essential system utilities
|
- name: Install essential system utilities
|
||||||
become: true
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
# name: "{{ base_packages }}"
|
# name: "{{ base_packages }}"
|
||||||
name:
|
name:
|
||||||
@@ -27,7 +25,8 @@
|
|||||||
- unattended-upgrades
|
- unattended-upgrades
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
#
|
||||||
# - name: Enable unattended-upgrades
|
# - name: Enable unattended-upgrades
|
||||||
# ansible.builtin.copy:
|
# ansible.builtin.copy:
|
||||||
# dest: /etc/apt/apt.conf.d/20auto-upgrades
|
# dest: /etc/apt/apt.conf.d/20auto-upgrades
|
||||||
@@ -36,3 +35,5 @@
|
|||||||
# 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
-18
@@ -1,8 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Install Docker
|
- name: Install Docker prerequisites
|
||||||
become: true
|
|
||||||
block:
|
|
||||||
- name: Install Docker prerequisites
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- ca-certificates
|
- ca-certificates
|
||||||
@@ -10,8 +7,9 @@
|
|||||||
- python3-debian ## needed for the deb822 module
|
- python3-debian ## needed for the deb822 module
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Add Docker official APT repository (DEB822 format)
|
- name: Add Docker official APT repository (DEB822 format)
|
||||||
ansible.builtin.deb822_repository:
|
ansible.builtin.deb822_repository:
|
||||||
name: docker
|
name: docker
|
||||||
types: deb
|
types: deb
|
||||||
@@ -20,8 +18,9 @@
|
|||||||
components: stable
|
components: stable
|
||||||
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
|
signed_by: "https://download.docker.com/linux/{{ ansible_facts['distribution'] | lower }}/gpg"
|
||||||
state: present
|
state: present
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Install Docker CE packages
|
- name: Install Docker CE packages
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- docker-ce
|
- docker-ce
|
||||||
@@ -31,41 +30,39 @@
|
|||||||
- docker-compose-plugin
|
- docker-compose-plugin
|
||||||
state: present
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Ensure Docker service is running and enabled
|
- 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: Configure deployment user for Docker
|
|
||||||
when: deployment_public_ssh_key is defined
|
|
||||||
become: true
|
become: true
|
||||||
block:
|
|
||||||
- name: Add deployment user to docker group
|
- name: Add deployment user to docker group
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: deployment
|
name: deployment
|
||||||
groups: docker
|
groups: docker
|
||||||
append: true
|
append: true
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Create target for docker compose
|
- name: Create target for docker compose files
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /opt/docker
|
path: /opt/docker
|
||||||
state: directory
|
state: directory
|
||||||
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
|
- name: Create appuser group
|
||||||
ansible.builtin.group:
|
ansible.builtin.group:
|
||||||
name: appuser
|
name: appuser
|
||||||
state: present
|
state: present
|
||||||
gid: 9999
|
gid: 9999
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Create appuser
|
- name: Create app user for secure container execution
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: appuser
|
name: appuser
|
||||||
state: present
|
state: present
|
||||||
@@ -74,3 +71,4 @@
|
|||||||
system: true
|
system: true
|
||||||
shell: /usr/sbin/nologin
|
shell: /usr/sbin/nologin
|
||||||
create_home: false
|
create_home: false
|
||||||
|
become: true
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Restart sshd
|
- name: Restart sshd
|
||||||
become: true
|
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: ssh
|
name: ssh
|
||||||
state: restarted
|
state: restarted
|
||||||
@@ -1,36 +1,20 @@
|
|||||||
---
|
---
|
||||||
- name: Harden SSH configuration
|
- name: Harden SSH configuration
|
||||||
become: true
|
ansible.builtin.import_role:
|
||||||
block:
|
name: devsec.hardening.ssh_hardening
|
||||||
- name: Create SSH drop-in directory
|
vars:
|
||||||
ansible.builtin.file:
|
ssh_permit_root_login: "no"
|
||||||
path: /etc/ssh/sshd_config.d
|
ssh_password_authentication: "no"
|
||||||
state: directory
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: "0755"
|
|
||||||
|
|
||||||
- name: Harden SSH configuration with drop-in template
|
- name: Install fail2ban
|
||||||
ansible.builtin.template:
|
|
||||||
src: sshd.conf.j2
|
|
||||||
dest: /etc/ssh/sshd_config.d/sshd.conf
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: "0644"
|
|
||||||
validate: /usr/sbin/sshd -t -f %s
|
|
||||||
notify: Restart sshd
|
|
||||||
|
|
||||||
- name: Enable fail2ban
|
|
||||||
become: true
|
|
||||||
block:
|
|
||||||
- name: Install fail2ban
|
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name:
|
name:
|
||||||
- fail2ban
|
- fail2ban
|
||||||
state: present
|
state: present
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Start fail2ban
|
- name: Start fail2ban
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: fail2ban
|
name: fail2ban
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: yes
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
## Disable root login
|
|
||||||
PermitRootLogin no
|
|
||||||
|
|
||||||
## Disable password authentication
|
|
||||||
PasswordAuthentication no
|
|
||||||
+10
-14
@@ -1,42 +1,38 @@
|
|||||||
---
|
---
|
||||||
- name: Set up primary sysadmin user
|
- name: Create primary sysadmin user
|
||||||
when: sysadmin_public_ssh_key is defined
|
|
||||||
become: true
|
|
||||||
block:
|
|
||||||
- name: Create sysadmin user
|
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: "{{ sysadmin_user }}"
|
name: "{{ sysadmin_user }}"
|
||||||
groups: sudo
|
groups: sudo
|
||||||
append: yes
|
append: yes
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
create_home: yes
|
create_home: yes
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Add SSH public key
|
- name: Add SSH public key for sysadmin
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
user: "{{ sysadmin_user }}"
|
user: "{{ sysadmin_user }}"
|
||||||
state: present
|
state: present
|
||||||
key: "{{ sysadmin_public_ssh_key }}"
|
key: "{{ sysadmin_public_ssh_key }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
- name: Allow passwordless sudo
|
- name: Allow passwordless sudo for sudo group
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
dest: /etc/sudoers.d/sudo-nopasswd
|
dest: /etc/sudoers.d/sudo-nopasswd
|
||||||
content: "%sudo 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
|
||||||
|
|
||||||
|
|
||||||
- name: Set up deployment user for CI/CD
|
|
||||||
when: deployment_public_ssh_key is defined
|
|
||||||
become: true
|
become: true
|
||||||
block:
|
|
||||||
- name: Create deployment user
|
- name: Create deployment user for CI/CD
|
||||||
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
|
- name: Add SSH public key for deployment user
|
||||||
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
|
||||||
Reference in new issue
Block a user