src.nth.io/

summaryrefslogtreecommitdiff
path: root/swapfile/tasks/main.yaml
blob: cec3755ab8e453e73ea8ca676712c6e22c58d89a (plain)
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
---

- name: check if swap file exists
  stat:
    path: "{{swapfile_path}}"
  register: swapfile_check

- name: create swap file
  become: yes
  command: "fallocate -l {{swapfile_size}} {{swapfile_path}}"
  when: not swapfile_check.stat.exists

- name: set swap file permissions
  become: yes
  file:
    path: "{{swapfile_path}}"
    mode: "0600"

- name: format swap file
  become: yes
  command: "mkswap {{swapfile_path}}"
  when: not swapfile_check.stat.exists

- name: write swap entry in fstab
  become: yes
  mount:
    name: "none"
    src: "{{swapfile_path}}"
    fstype: "swap"
    opts: "sw"
    passno: 0
    dump: 0
    state: "present"

- name: turn on swap
  become: yes
  command: "swapon {{swapfile_path}}"
  when: not swapfile_check.stat.exists