From 43ce9b0b40e6f5fe136913b85d00dae4f37aa1fe Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Sat, 12 Aug 2023 12:13:49 +0200 Subject: [PATCH] add swapfile for lewis --- ansible/hypervisors.yml | 27 ++++++++++++++++++++++ ansible/inventory/host_vars/lewis/swap.yml | 1 + 2 files changed, 28 insertions(+) create mode 100644 ansible/inventory/host_vars/lewis/swap.yml diff --git a/ansible/hypervisors.yml b/ansible/hypervisors.yml index 69d4e38..e569b84 100644 --- a/ansible/hypervisors.yml +++ b/ansible/hypervisors.yml @@ -65,3 +65,30 @@ hosts: lewis roles: - {role: borg, tags: borg} + +- hosts: lewis + + tasks: + - name: Check if swap file exists + stat: + path: "{{ swapfile_loc }}" + register: swapfile + + - name: Create swap file + block: + - name: Create file + command: + cmd: "dd if=/dev/zero of={{ swapfile_loc }} bs=1024 count=2M" + + - name: Format swap file + command: + cmd: "mkswap {{ swapfile_loc }}" + when: not swapfile.stat.exists + + - name: Mount swap file + mount: + src: "{{ swapfile_loc }}" + path: swap + fstype: swap + opts: sw + state: present diff --git a/ansible/inventory/host_vars/lewis/swap.yml b/ansible/inventory/host_vars/lewis/swap.yml new file mode 100644 index 0000000..1c9c119 --- /dev/null +++ b/ansible/inventory/host_vars/lewis/swap.yml @@ -0,0 +1 @@ +swapfile_loc: /swapfile.img