Skip to content

Instantly share code, notes, and snippets.

@drybjed
Created June 23, 2014 16:22
Show Gist options
  • Save drybjed/7dddfa323f9d877c024a to your computer and use it in GitHub Desktop.
Save drybjed/7dddfa323f9d877c024a to your computer and use it in GitHub Desktop.
---
- name: ensure swap file is allocated
command: dd if=/dev/zero of=/swapfile bs=1M count={{ common_swap_size }} creates=/swapfile
when: ansible_swaptotal_mb < 1
register: swapfile_init
- name: ensure swap file is created
command: mkswap /swapfile
when: swapfile_init is defined and swapfile_init.changed
- name: ensure swap file is added to fstab
action: lineinfile dest=/etc/fstab regexp="swapfile" line="/swapfile none swap sw 0 0" state=present
when: swapfile_init is defined and swapfile_init.changed
- name: ensure swap file is enabled
command: swapon -a
when: swapfile_init is defined and swapfile_init.changed
- name: ensure swappiness is set
shell: echo 0 | sudo tee /proc/sys/vm/swappiness
when: swapfile_init is defined and swapfile_init.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment