Files
convert-images-for-web/roles/common/tasks/swap.yml

69 lines
1.7 KiB
YAML

---
- name: test for swap partition
shell: swapon -s | grep -E "^/mnt/swapfile"
register: swapfile
ignore_errors: yes
- name: disable any other swap
shell: swapoff -a
when: swapfile|failed
- name: swap - remove current swaps from fstab
lineinfile:
dest: /etc/fstab
regexp: '^\/[\S]+\s+none\s+swap '
state: absent
when: swapfile|failed
- name: create swapfile
when: swapfile|failed
shell: fallocate -l 4G /mnt/swapfile
ignore_errors: yes
- name: set swapfile permissions
when: swapfile|failed
file: path=/mnt/swapfile
owner=root
group=root
mode=0600
- name: prepare swapfile
when: swapfile|failed
shell: mkswap /mnt/swapfile
ignore_errors: yes
- name: enable swap
when: swapfile|failed
shell: swapon /mnt/swapfile
ignore_errors: yes
- name: add swapfile
when: swapfile|failed
lineinfile: dest=/etc/fstab
regexp="^/mnt/swapfile"
state=present
line="/mnt/swapfile none swap sw 0 0"
- name: set swappiness (temporarily)
when: swapfile|failed
shell: echo 10 > /proc/sys/vm/swappiness
ignore_errors: yes
- name: set swappiness (permanent)
when: swapfile|failed
lineinfile: dest=/etc/sysctl.conf
regexp="^vm.swappiness"
state=present
line="vm.swappiness = 10"
- name: set cache pressure (temporarily)
when: swapfile|failed
shell: echo 50 > /proc/sys/vm/vfs_cache_pressure
ignore_errors: yes
- name: set cache pressure (permanent)
when: swapfile|failed
lineinfile: dest=/etc/sysctl.conf
regexp="^vm.vfs_cache_pressure"
state=present
line="vm.vfs_cache_pressure = 50"