Only create swapfile if there isnt one already

This commit is contained in:
2016-02-12 10:29:56 -05:00
parent 68ac01cd6d
commit 8ea8f41d77

View File

@@ -70,26 +70,55 @@
- name: Add update line to update script - 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 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 - name: test for swap partition
shell: fallocate -l 4G /swapfile shell: swapon -s | grep -E "^/"
register: swapfile
ignore_errors: yes
- name: Secure swapfile - name: create swapfile
shell: chmod 600 /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 shell: mkswap /swapfile
- name: Enable swap file - name: enable swap
when: swapfile|failed
shell: swapon /swapfile shell: swapon /swapfile
- name: Fix swappiness - name: add swapfile
shell: echo "sysctl vm.swappiness=10" >> /etc/sysctl.conf when: swapfile|failed
lineinfile: dest=/etc/fstab
regexp="^/swapfile"
state=present
line="/swapfile none swap sw 0 0"
- name: Set current swappiness - name: set swappiness (temporarily)
shell: sysctl vm.swappiness=10 when: swapfile|failed
shell: echo 10 | tee /proc/sys/vm/swappiness
- name: Fix cache pressure - name: set swappiness (permanent)
shell: echo "sysctl vm.vfs_cache_pressure=50" >> /etc/sysctl.conf when: swapfile|failed
lineinfile: dest=/etc/sysctl.conf
regexp="^vm.swappiness"
state=present
line="vm.swappiness = 10"
- name: Set current cache pressure - name: set cache pressure (temporarily)
shell: sysctl vm.vfs_cache_pressure=50 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"