Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce9b5d58b4 | ||
|
|
2c29ea2780 |
@@ -1,5 +1,5 @@
|
|||||||
# Ansible Collection
|
# 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.
|
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`.
|
||||||
Currently only supports Debian-based systems.
|
- A ready-to-use playbook configured by passing CLI vars `--extra-vars "ansible_host=${HOST_IP}` e.g. through CI / CD.
|
||||||
|
|||||||
+2
-3
@@ -3,9 +3,8 @@
|
|||||||
namespace: studio
|
namespace: studio
|
||||||
name: ansible
|
name: ansible
|
||||||
readme: README.md
|
readme: README.md
|
||||||
version: 0.0.1
|
version: 1.0.0
|
||||||
authors:
|
authors:
|
||||||
- Studio Vitali
|
- Studio Vitali
|
||||||
description: Studio Ansible collection containing common roles
|
description: Studio Ansible collection containing common roles
|
||||||
license:
|
license: MIT
|
||||||
- MIT
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[target]
|
||||||
|
target_host ansible_host="{{ ansible_host }}"
|
||||||
|
|
||||||
|
[all:vars]
|
||||||
|
ansible_user="{{ ansible_user }}"
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
requires_ansible: ">=2.15.0"
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: Setup machines
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- base
|
||||||
|
- users
|
||||||
|
- security
|
||||||
|
- docker
|
||||||
|
# - backup
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
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
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
- 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
|
||||||
@@ -35,3 +37,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?
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
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: ""
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
||||||
+16
-57
@@ -1,76 +1,35 @@
|
|||||||
---
|
---
|
||||||
- name: Install Docker
|
- name: Install necessary Docker packages
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- docker.io
|
||||||
|
- docker-compose
|
||||||
|
state: present
|
||||||
|
when: ansible_facts['os_family'] == "Debian" ## Debian / Ubuntu
|
||||||
become: true
|
become: true
|
||||||
block:
|
|
||||||
- name: Install Docker prerequisites
|
|
||||||
ansible.builtin.apt:
|
|
||||||
name:
|
|
||||||
- ca-certificates
|
|
||||||
- curl
|
|
||||||
- python3-debian ## needed for the deb822 module
|
|
||||||
state: present
|
|
||||||
update_cache: true
|
|
||||||
|
|
||||||
- name: Add Docker official APT repository (DEB822 format)
|
- name: Ensure Docker service is running
|
||||||
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: Configure deployment user for Docker
|
- name: Create docker user for container execution
|
||||||
when: deployment_public_ssh_key is defined
|
|
||||||
become: true
|
|
||||||
block:
|
|
||||||
- name: Add deployment user to docker group
|
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: deployment
|
name: docker
|
||||||
|
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:
|
||||||
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
|
|
||||||
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
|
- name: Restart sshd
|
||||||
ansible.builtin.service:
|
ansible.builtin.service:
|
||||||
name: ssh
|
name: sshd
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
---
|
---
|
||||||
- name: Harden SSH configuration
|
- name: Create SSH drop-in directory
|
||||||
become: true
|
|
||||||
block:
|
|
||||||
- name: Create SSH drop-in directory
|
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/ssh/sshd_config.d
|
path: /etc/ssh/sshd_config.d
|
||||||
state: directory
|
state: directory
|
||||||
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:
|
||||||
src: sshd.conf.j2
|
src: sshd.conf.j2
|
||||||
dest: /etc/ssh/sshd_config.d/sshd.conf
|
dest: /etc/ssh/sshd_config.d/sshd.conf
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
validate: "sshd -t -f %s"
|
||||||
notify: Restart sshd
|
notify: Restart sshd
|
||||||
|
|
||||||
- name: Enable fail2ban
|
|
||||||
become: true
|
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"
|
||||||
|
|||||||
+25
-29
@@ -1,42 +1,38 @@
|
|||||||
---
|
---
|
||||||
- name: Set up primary sysadmin user
|
# - name: Create primary admin user
|
||||||
when: sysadmin_public_ssh_key is defined
|
# ansible.builtin.user:
|
||||||
become: true
|
# name: sysadmin
|
||||||
block:
|
# groups: sudo
|
||||||
- name: Create sysadmin user
|
# append: yes
|
||||||
ansible.builtin.user:
|
# shell: /bin/bash
|
||||||
name: "{{ sysadmin_user }}"
|
# create_home: yes
|
||||||
groups: sudo
|
# become: true
|
||||||
append: yes
|
|
||||||
shell: /bin/bash
|
|
||||||
create_home: yes
|
|
||||||
|
|
||||||
- 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
|
||||||
state: present
|
# state: present
|
||||||
key: "{{ sysadmin_public_ssh_key }}"
|
# key: "{{ sysadmin_public_ssh_key }}"
|
||||||
|
# become: true
|
||||||
|
|
||||||
- name: Allow passwordless sudo
|
# - 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
|
||||||
|
|
||||||
|
- 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
|
- 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