Fix swap on linux+btrfs

This commit is contained in:
Gašper Fele-Žorž 2025-09-12 15:43:10 +02:00
parent 0f8f8486f0
commit 09138174d4

View file

@ -1,6 +1,55 @@
- name: Enable multiarch
command: dpkg --add-architecture i386
- name: Create swap btrfs subvolume
command: btrfs subvolume create /swap
ignore_errors: True
- name: Create swap directory if it does not exist
file:
path: /swap
state: directory
- name: Create btrfs swap
command: btrfs filesystem mkswapfile --size 4g /swap/swap.img
ignore_errors: True
- name: Create swap image if it does not exist
shell: fallocate -l 4G /swap/swap.img && mkswap /swap/swap.img
args:
creates: /swap/swap.img
ignore_errors: True
- name: Change swap file permissions
file: path="/swap/swap.img"
owner=root
group=root
mode=0600
- name: Write swap entry in fstab
mount: name=none
src=/swap/swap.img
fstype=swap
opts=sw
passno=0
dump=0
state=present
- name: Activate swap
command: "swapon /swap/swap.img"
ignore_errors: True
- name: Make sure default swap entry does not exist
mount:
path: none
src: /swap.img
fstype: swap
state: absent
- name: Make sure default swap is not used
command: swapoff /swap/swap.img
ignore_errors: True
- name: Install generally useful packages
apt:
name: