diff --git a/roles/crawler/tasks/enable-swap-for-tb.yml b/roles/crawler/tasks/enable-swap-for-tb.yml new file mode 100644 index 00000000..60810d11 --- /dev/null +++ b/roles/crawler/tasks/enable-swap-for-tb.yml @@ -0,0 +1,32 @@ +--- +# Tor Browser requires swap and may experience irregular errors without it. +# Credit to Parménides GV (https://github.com/parmegv) for this tasklist. + +- name: Create swap file. + command: fallocate -l {{ (ansible_memtotal_mb / 1000 / 2)|round(0, 'ceil')|int }}G /swapfile + creates=/swapfile + when: ansible_swaptotal_mb < 1 + register: swapfile_created + +- name: Set swapfile permissions. + file: path=/swapfile + mode=0600 + when: swapfile_created.changed + +- name: Format swapfile as swap. + command: mkswap /swapfile + when: swapfile_created.changed + +- name: Add swap to fstab. + mount: name=swapfile + src=/swapfile + fstype=swap + opts=sw + passno=0 + dump=0 + state=present + when: swapfile_created.changed + +- name: Enable swap. + command: swapon /swapfile + when: swapfile_created.changed diff --git a/roles/crawler/tasks/main.yml b/roles/crawler/tasks/main.yml index 687b64a8..2ecd59cc 100644 --- a/roles/crawler/tasks/main.yml +++ b/roles/crawler/tasks/main.yml @@ -18,6 +18,7 @@ - include: configure.yml tags: configure - include: download-verify-tbb.yml + - include: enable-swap-for-tb.yml - include: download-verify-tor.yml - include: build-install-tor.yml - include: install-systemd-unit.yml