Add swap.yml
This commit is contained in:
32
swap.yml
Normal file
32
swap.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
- name: Create swap file if not present
|
||||||
|
hosts: all
|
||||||
|
become: yes
|
||||||
|
vars:
|
||||||
|
swap_file: /swapfile
|
||||||
|
swap_size_mb: 2048
|
||||||
|
tasks:
|
||||||
|
- name: Allocate swap file
|
||||||
|
command: fallocate -l {{ swap_size_mb }}M {{ swap_file }}
|
||||||
|
args:
|
||||||
|
creates: "{{ swap_file }}"
|
||||||
|
|
||||||
|
- name: Secure swap file
|
||||||
|
file:
|
||||||
|
path: "{{ swap_file }}"
|
||||||
|
owner: root
|
||||||
|
mode: '0600'
|
||||||
|
|
||||||
|
- name: Make swap
|
||||||
|
command: mkswap {{ swap_file }}
|
||||||
|
|
||||||
|
- name: Enable swap
|
||||||
|
command: swapon {{ swap_file }}
|
||||||
|
|
||||||
|
- name: Ensure swap on reboot
|
||||||
|
mount:
|
||||||
|
name: none
|
||||||
|
src: "{{ swap_file }}"
|
||||||
|
fstype: swap
|
||||||
|
opts: sw
|
||||||
|
state: present
|
||||||
Reference in New Issue
Block a user