-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap.yml
73 lines (59 loc) · 1.72 KB
/
swap.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
- hosts: all
become: true
tasks:
- name: set swap_file variable
set_fact:
swap_file: /swapfile.swap
- name: check if swap file exists
stat:
path: "{{ swap_file }}"
register: swap_file_check
- name: create swap file
command: fallocate -l 8G {{ swap_file }}
when: not swap_file_check.stat.exists
- name: Create swap space
command: dd if=/dev/zero of=/extraswap bs=1M count=8192
when: not swap_file_check.stat.exists
- name: set permissions on swap file
file:
path: "{{ swap_file }}"
mode: 0600
- name: format swap file
command: /usr/sbin/mkswap {{ swap_file }}
when: not swap_file_check.stat.exists
- name: add to fstab
lineinfile:
dest: /etc/fstab
regexp: "{{ swap_file }}"
line: "{{ swap_file }} none swap sw 0 0"
- name: turn on swap
command: /usr/sbin/swapon -a
- name: set swapiness
sysctl:
name: vm.swappiness
value: "80"
- name: Check if zswap is enabled
lineinfile:
backup: true
path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX=".*zswap.enabled=1.*'
state: absent
check_mode: true
register: grub_cmdline_check
changed_when: false
- name: Enable zswap at boot
lineinfile:
backrefs: true
path: /etc/default/grub
regexp: "^(GRUB_CMDLINE_LINUX=\".*)\"$"
line: '\1 zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=25 zswap.zpool=z3fold"'
when: grub_cmdline_check.found == 0
- name: update-grub
command: /usr/sbin/update-grub2
- name: Add Modules to Kernel
lineinfile:
dest: /etc/initramfs-tools/modules
regexp: "zstd"
line: "zstd\nz3fold"
- name: Update initramfs
command: update-initramfs -u