Skip to content

Instantly share code, notes, and snippets.

@rjsalts
Last active August 29, 2015 14:20
Show Gist options
  • Save rjsalts/72f203cdadfd226776a4 to your computer and use it in GitHub Desktop.
Save rjsalts/72f203cdadfd226776a4 to your computer and use it in GitHub Desktop.
---
- name: Change the swap to given size in gigabytes
hosts: all
user: root
vars:
size: 4
tasks:
- name: find existing swap size
shell: lvs --noheadings --separator , --units g | grep swap_1 | cut -f 4 -d ,
register: swap_size
- name: disable swap
command: swapoff -a
when: swap_size.stdout != "{{ size }}.00g"
notify: activate swap
- name: resize swap lvol
lvol: vg={{ ansible_hostname }}-vg lv=swap_1 size={{ size }}G force=yes
notify: mkswap
handlers:
- name: mkswap
command: mkswap /dev/{{ansible_hostname}}-vg/swap_1
- name: activate swap
command: swapon -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment