Skip to content

Instantly share code, notes, and snippets.

@metasikander
Created February 20, 2020 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasikander/f5bb6d57195db276443d5faea6ac69a1 to your computer and use it in GitHub Desktop.
Save metasikander/f5bb6d57195db276443d5faea6ac69a1 to your computer and use it in GitHub Desktop.
an ansible playbook to set up a swapfile
---
- name: Swapfile playbook
hosts: all
become: yes
tasks:
- name: create swapfile
command: fallocate -l 2G /swapfile
args:
creates: /swapfile
- name: swapfile access rights
file:
path: /swapfile
owner: root
group: root
mode: 0600
- name: mkswap
command: mkswap /swapfile
ignore_errors: yes
- name: swapon
command: swapon /swapfile
ignore_errors: yes
- name: add to fstab
lineinfile:
path: /etc/fstab
line: /swapfile none swap defaults 0 0
create: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment