Add swap.yml

This commit is contained in:
2025-07-20 19:01:42 +02:00
parent 4248d156bf
commit c77802500f

32
swap.yml Normal file
View 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