diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 9881f29..1498765 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -70,26 +70,55 @@ - name: Add update line to update script shell: echo apt-get update && apt-get upgrade -y && apt-get clean && apt-get autoclean && apt-get autoremove -y && apt-get update >> /etc/cron.daily/update.sh -- name: Allocate swap file - shell: fallocate -l 4G /swapfile +- name: test for swap partition + shell: swapon -s | grep -E "^/" + register: swapfile + ignore_errors: yes -- name: Secure swapfile - shell: chmod 600 /swapfile +- name: create swapfile + when: swapfile|failed + shell: fallocate -l 4G /swapfile -- name: Make swap file +- name: set swapfile permissions + when: swapfile|failed + file: path=/swapfile + owner=root + group=root + mode=0600 + +- name: prepare swapfile + when: swapfile|failed shell: mkswap /swapfile -- name: Enable swap file +- name: enable swap + when: swapfile|failed shell: swapon /swapfile -- name: Fix swappiness - shell: echo "sysctl vm.swappiness=10" >> /etc/sysctl.conf +- name: add swapfile + when: swapfile|failed + lineinfile: dest=/etc/fstab + regexp="^/swapfile" + state=present + line="/swapfile none swap sw 0 0" -- name: Set current swappiness - shell: sysctl vm.swappiness=10 +- name: set swappiness (temporarily) + when: swapfile|failed + shell: echo 10 | tee /proc/sys/vm/swappiness -- name: Fix cache pressure - shell: echo "sysctl vm.vfs_cache_pressure=50" >> /etc/sysctl.conf +- name: set swappiness (permanent) + when: swapfile|failed + lineinfile: dest=/etc/sysctl.conf + regexp="^vm.swappiness" + state=present + line="vm.swappiness = 10" -- name: Set current cache pressure - shell: sysctl vm.vfs_cache_pressure=50 +- name: set cache pressure (temporarily) + when: swapfile|failed + shell: echo 50 | tee /proc/sys/vm/vfs_cache_pressure + +- name: set cache pressure (permanent) + when: swapfile|failed + lineinfile: dest=/etc/sysctl.conf + regexp="^vm.vfs_cache_pressure" + state=present + line="vm.swappiness = 50"