swapfile/tasks/main.yaml
author Luke Hoersten <luke@hoersten.org>
Mon, 07 Oct 2024 23:31:51 -0500
changeset 239 c3e3169399a8
parent 230 07f08cc98da0
permissions -rw-r--r--
Updated java version and disabled geyser due to too old jde.

---

- 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