src.nth.io/

summaryrefslogtreecommitdiff
path: root/swapfile
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2024-02-10 15:41:05 -0600
committerLuke Hoersten <[email protected]>2024-02-10 15:41:05 -0600
commiteec49748a99c889550658fa82cde04c7c1d7c1de (patch)
tree8ad537bab029a7305f191c61c42d236f4218ed26 /swapfile
parentde23e66fdded8d2884de32267e09b128d2680bfa (diff)
Added swapfile role.
Diffstat (limited to 'swapfile')
-rw-r--r--swapfile/tasks/main.yaml38
1 files changed, 38 insertions, 0 deletions
diff --git a/swapfile/tasks/main.yaml b/swapfile/tasks/main.yaml
new file mode 100644
index 0000000..cec3755
--- /dev/null
+++ b/swapfile/tasks/main.yaml
@@ -0,0 +1,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