From 9459c74dce55a64fdb4f6bc753d5ab037ab02a90 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Fri, 10 Aug 2018 11:43:48 +0000 Subject: [PATCH] Remove any other swap than the one I'm creating --- roles/common/tasks/main.yml | 61 ++------------------------------ roles/common/tasks/swap.yml | 69 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 58 deletions(-) create mode 100644 roles/common/tasks/swap.yml diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index ddf9fa8..c0416c2 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -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 \ No newline at end of file diff --git a/roles/common/tasks/swap.yml b/roles/common/tasks/swap.yml new file mode 100644 index 0000000..7c68b04 --- /dev/null +++ b/roles/common/tasks/swap.yml @@ -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" \ No newline at end of file