Remove any other swap than the one I'm creating

This commit is contained in:
2018-08-10 11:43:48 +00:00
parent 2ba508e1b5
commit 9459c74dce
2 changed files with 72 additions and 58 deletions

View File

@@ -118,64 +118,6 @@
state: mounted
fstype: nfs
ignore_errors: true
- name: test for swap partition
shell: swapon -s | grep -E "^/"
register: swapfile
ignore_errors: yes
- name: create swapfile
when: swapfile|failed
shell: fallocate -l 4G /swapfile
ignore_errors: yes
- 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
ignore_errors: yes
- name: enable swap
when: swapfile|failed
shell: swapon /swapfile
ignore_errors: yes
- name: add swapfile
when: swapfile|failed
lineinfile: dest=/etc/fstab
regexp="^/swapfile"
state=present
line="/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"
- name: Set hostname
hostname:
@@ -187,3 +129,6 @@
regexp: '(\s+)ubuntu(\s+.*)?$'
replace: '\1{{ inventory_hostname }}\2'
backup: yes
- name: swap
include: swap.yml

View File

@@ -0,0 +1,69 @@
---
- name: test for swap partition
shell: swapon -s | grep -E "^/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 /swapfile
ignore_errors: yes
- 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
ignore_errors: yes
- name: enable swap
when: swapfile|failed
shell: swapon /swapfile
ignore_errors: yes
- name: add swapfile
when: swapfile|failed
lineinfile: dest=/etc/fstab
regexp="^/swapfile"
state=present
line="/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"