Skip to content
Snippets Groups Projects
Commit caf211f2 authored by nimrod's avatar nimrod
Browse files

Seperate the long debian-server role to smaller tasks files.

parent c5fd0196
Branches
No related tags found
No related merge requests found
---
- name: Copy btrfs backup script
copy:
dest: /usr/local/sbin/btrfs-backup
group: root
mode: preserve
owner: root
src: btrfs-backup
- name: Create btrfs scrub services
# yamllint disable rule:line-length
loop: &btrfs_devices |-
{{ ansible_mounts|selectattr("fstype", "equalto", "btrfs")|map(attribute="device")|unique }}
# yamllint enable rule:line-length
ansible.builtin.template:
dest: /etc/systemd/system/scrub{{ name }}.service
mode: 0o0644
src: scrub.service.j2
vars: &btrfs_vars
device: '{{ item }}'
name: '{{ item|replace("/", "_") }}'
tags: [scrub]
- name: Create btrfs scrub timers
loop: *btrfs_devices
ansible.builtin.template:
dest: /etc/systemd/system/scrub{{ name }}.timer
mode: 0o0644
src: scrub.timer.j2
vars: *btrfs_vars
tags: [scrub]
- name: Enable the btrfs scrub timers
loop: *btrfs_devices
ansible.builtin.systemd:
enabled: true
name: scrub{{ name }}.timer
state: started
vars: *btrfs_vars
tags: [scrub]
---
- name: Disable cgroup2 for Docker
lineinfile:
backup: true
line: |-
GRUB_CMDLINE_LINUX_DEFAULT="quiet systemd.unified_cgroup_hierarchy=0"
path: /etc/default/grub
notify:
- Update GRUB
- name: Copy the script to start stopped container after a restart
copy:
dest: /usr/share/docker.io/restart-containers
mode: preserve
src: docker-restart
- name: Create a drop-in directory for the Docker service
file:
path: /etc/systemd/system/docker.service.d
mode: 0o0755
state: directory
- name: Restart stopped containers after a restart
copy:
content: |
[Service]
ExecStartPost=/usr/share/docker.io/restart-containers
dest: /etc/systemd/system/docker.service.d/restart-containers.conf
mode: 0o0644
notify:
- Systemd daemon reload
- name: Allow default Docker network access to local services
community.general.ufw:
direction: in
interface: docker0
rule: allow
- name: Set UID/GID mapping range
loop:
- /etc/subgid
- /etc/subuid
copy:
content: |
nimrod:100000:65536
dest: |-
{{ item }}
group: root
mode: 0o0644
owner: root
- name: Allow unprivileged user namespaces
ansible.posix.sysctl:
name: kernel/unprivileged_userns_clone
state: present
value: "1"
...@@ -6,15 +6,6 @@ ...@@ -6,15 +6,6 @@
- ansible_distribution_major_version|int >= 10 - ansible_distribution_major_version|int >= 10
- ansible_service_mgr == "systemd" - ansible_service_mgr == "systemd"
- name: Disable cgroup2 for Docker
lineinfile:
backup: true
line: |-
GRUB_CMDLINE_LINUX_DEFAULT="quiet systemd.unified_cgroup_hierarchy=0"
path: /etc/default/grub
notify:
- Update GRUB
- name: Enable the backports repo - name: Enable the backports repo
loop: loop:
- deb - deb
...@@ -56,51 +47,17 @@ ...@@ -56,51 +47,17 @@
- ufw - ufw
state: present state: present
- name: Copy the script to start stopped container after a restart
copy:
dest: /usr/share/docker.io/restart-containers
mode: preserve
src: docker-restart
- name: Create a drop-in directory for the Docker service
file:
path: /etc/systemd/system/docker.service.d
mode: 0o0755
state: directory
- name: Restart stopped containers after a restart
copy:
content: |
[Service]
ExecStartPost=/usr/share/docker.io/restart-containers
dest: /etc/systemd/system/docker.service.d/restart-containers.conf
mode: 0o0644
notify:
- Systemd daemon reload
- name: Rate limit SSH - name: Rate limit SSH
community.general.ufw: community.general.ufw:
rule: limit rule: limit
port: ssh port: ssh
proto: tcp proto: tcp
- name: Allow default Docker network access to local services
community.general.ufw:
direction: in
interface: docker0
rule: allow
- name: Enable UFW - name: Enable UFW
community.general.ufw: community.general.ufw:
default: reject default: reject
state: enabled state: enabled
- name: Allow unprivileged user namespaces
ansible.posix.sysctl:
name: kernel/unprivileged_userns_clone
state: present
value: "1"
- name: Allow more inotify watches - name: Allow more inotify watches
ansible.posix.sysctl: ansible.posix.sysctl:
name: fs.inotify.max_user_watches name: fs.inotify.max_user_watches
...@@ -128,80 +85,6 @@ ...@@ -128,80 +85,6 @@
regexp: swap regexp: swap
state: absent state: absent
- name: Set UID/GID mapping range
loop:
- /etc/subgid
- /etc/subuid
copy:
content: |
nimrod:100000:65536
dest: |-
{{ item }}
group: root
mode: 0o0644
owner: root
- name: Create my www directory
file:
group: www-data
mode: 0o0755
owner: www-data
path: /var/www
state: directory
- name: Create an SSL directory under /var
file:
group: root
mode: 0o0755
owner: root
path: /var/ssl
state: directory
# I know that I can use Ansible modules instead of calling OpenSSL directly, but
# with the command module I can easily skip the task if the private key or the
# certificate already exist. The point is to create an SSL and self-signed
# certificate only as a bootstrap step. Once there is an existing (and assumed
# valid) certificate, don't overwrite it.
- name: Create private SSL key
command:
cmd: openssl genrsa -out /var/ssl/site.key 4096
creates: /var/ssl/site.key
- name: Make sure the private key is accessible
file:
mode: 0o0444
path: /var/ssl/site.key
state: file
- name: Create SSL certificate
command:
cmd: >-
openssl
req
-x509
-out /var/ssl/site.crt
-nodes
-key /var/ssl/site.key
-batch
creates: /var/ssl/site.crt
- name: Create Diffie-Hellman Parameters file
community.crypto.openssl_dhparam:
force: false
mode: 0o0644
path: /var/ssl/dhparams
size: 4096
state: present
- name: Copy btrfs backup script
copy:
dest: /usr/local/sbin/btrfs-backup
group: root
mode: preserve
owner: root
src: btrfs-backup
- name: Mail aliases - name: Mail aliases
loop: loop:
- root - root
...@@ -235,34 +118,14 @@ ...@@ -235,34 +118,14 @@
name: update.timer name: update.timer
state: started state: started
- name: Create btrfs scrub services - name: Include Docker tasks
# yamllint disable rule:line-length ansible.builtin.include_tasks:
loop: &btrfs_devices |- file: docker.yml
{{ ansible_mounts|selectattr("fstype", "equalto", "btrfs")|map(attribute="device")|unique }}
# yamllint enable rule:line-length
ansible.builtin.template:
dest: /etc/systemd/system/scrub{{ name }}.service
mode: 0o0644
src: scrub.service.j2
vars: &btrfs_vars
device: '{{ item }}'
name: '{{ item|replace("/", "_") }}'
tags: [scrub]
- name: Create btrfs scrub timers - name: Include web tasks
loop: *btrfs_devices ansible.builtin.include_tasks:
ansible.builtin.template: file: web.yml
dest: /etc/systemd/system/scrub{{ name }}.timer
mode: 0o0644
src: scrub.timer.j2
vars: *btrfs_vars
tags: [scrub]
- name: Enable the btrfs scrub timers - name: Include btrfs tasks
loop: *btrfs_devices ansible.builtin.include_tasks:
ansible.builtin.systemd: file: btrfs.yml
enabled: true
name: scrub{{ name }}.timer
state: started
vars: *btrfs_vars
tags: [scrub]
---
- name: Create my www directory
file:
group: www-data
mode: 0o0755
owner: www-data
path: /var/www
state: directory
- name: Create an SSL directory under /var
file:
group: root
mode: 0o0755
owner: root
path: /var/ssl
state: directory
# I know that I can use Ansible modules instead of calling OpenSSL directly, but
# with the command module I can easily skip the task if the private key or the
# certificate already exist. The point is to create an SSL and self-signed
# certificate only as a bootstrap step. Once there is an existing (and assumed
# valid) certificate, don't overwrite it.
- name: Create private SSL key
command:
cmd: openssl genrsa -out /var/ssl/site.key 4096
creates: /var/ssl/site.key
- name: Make sure the private key is accessible
file:
mode: 0o0444
path: /var/ssl/site.key
state: file
- name: Create SSL certificate
command:
cmd: >-
openssl
req
-x509
-out /var/ssl/site.crt
-nodes
-key /var/ssl/site.key
-batch
creates: /var/ssl/site.crt
- name: Create Diffie-Hellman Parameters file
community.crypto.openssl_dhparam:
force: false
mode: 0o0644
path: /var/ssl/dhparams
size: 4096
state: present
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment