diff --git a/host_vars/akatosh.yml b/host_vars/akatosh.yml index 573a0fe..81fbaa4 100644 --- a/host_vars/akatosh.yml +++ b/host_vars/akatosh.yml @@ -4,6 +4,9 @@ users: - jp - lourens - guus +# nightingale's analyzer peaks around 11G RSS during forced alignment, on 11G of RAM. +swapfile_size_gb: 24 + cloud_nginx_tls: true cloud_nginx_sites: - name: nextcloud diff --git a/playbook.yml b/playbook.yml index 4bff292..5f5817d 100644 --- a/playbook.yml +++ b/playbook.yml @@ -117,6 +117,8 @@ group: aurbis mode: "0775" loop: [nextcloud, hdwiki, gitea, authentik, drone, "hoekveen.net"] + - import_tasks: tasks/swapfile.yml + tags: swap - import_tasks: tasks/nextcloud.yml tags: nextcloud - import_tasks: tasks/hdwiki.yml diff --git a/tasks/swapfile.yml b/tasks/swapfile.yml new file mode 100644 index 0000000..2b9a558 --- /dev/null +++ b/tasks/swapfile.yml @@ -0,0 +1,46 @@ +- name: Check swapfile + stat: + path: /swapfile + register: swapfile + +- name: Size swapfile + when: not swapfile.stat.exists or swapfile.stat.size != swapfile_size_gb | int * 1024 * 1024 * 1024 + block: + - name: Disable swapfile + command: swapoff /swapfile + when: swapfile.stat.exists + changed_when: true + - name: Remove old swapfile + file: + path: /swapfile + state: absent + - name: Allocate swapfile + command: fallocate -l {{ swapfile_size_gb }}G /swapfile + changed_when: true + - name: Format swapfile + command: mkswap /swapfile + changed_when: true + +- name: Restrict swapfile permissions + file: + path: /swapfile + owner: root + group: root + mode: "0600" + +- name: Persist swapfile in fstab + ansible.posix.mount: + src: /swapfile + path: none + fstype: swap + opts: sw + state: present + +- name: Check active swap + command: swapon --show=NAME --noheadings + register: swapfile_active + changed_when: false + +- name: Enable swapfile + command: swapon /swapfile + when: "'/swapfile' not in swapfile_active.stdout_lines"