cri-o/contrib/test/integration/swap.yml
Chris Evich b198c57cfb integration-playbook: Idempotent Swapping
If the playbook is run multiple times or a host already has
swap configured, re-adding swap over the existing file
will cause untold problems.  Also, it will not persist across
reboots unless added to fstab.

Avoid this by checking if any swap is active. If not
create a unique swapfile and format it.  Then enable
it to persist across reboots.

Signed-off-by: Chris Evich <cevich@redhat.com>
2017-10-18 13:42:07 -04:00

42 lines
1.1 KiB
YAML

---
- name: Obtain current state of swap
command: swapon --noheadings --show=NAME
register: swapon
- name: Setup swap if none already, to prevent kernel firing off the OOM killer
block:
- name: A unique swapfile path is generated
command: mktemp --tmpdir=/root swapfile_XXX
register: swapfilepath
- name: Swap file path is buffered
set_fact:
swapfilepath: '{{ swapfilepath.stdout | trim }}'
- name: Set swap file permissions
file:
path: "{{ swapfilepath }}"
owner: root
group: root
mode: 0600
- name: Swapfile padded to swapfile_size & timed to help debug any performance problems
shell: 'time dd if=/dev/zero of={{ swapfilepath }} bs={{ swapfileGB }}M count=1024'
- name: Swap file is formatted
command: 'mkswap {{ swapfilepath }}'
- name: Write swap entry in fstab
mount:
path: none
src: "{{ swapfilepath }}"
fstype: swap
opts: sw
state: present
- name: Mount swap
command: "swapon -a"
when: not (swapon.stdout_lines | length)