From 58011fb8df29f92c11f1e9a4ea5f940e20af41c4 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 3 Nov 2023 10:27:46 +0100 Subject: [PATCH 1/3] Mask systemd swap.target do disable swap This is a more generic way to disable swap, since it pulls .swap units in systemd distributions; fstab is only one way to generate .swap units. --- roles/kubernetes/preinstall/tasks/0010-swapoff.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml index c603f37b1a9..1ac69c06ec3 100644 --- a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml +++ b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml @@ -1,12 +1,8 @@ --- -- name: Remove swapfile from /etc/fstab - ansible.posix.mount: - name: "{{ item }}" - fstype: swap - state: absent - loop: - - swap - - none +- name: Mask swap.target (persist swapoff) + ansible.builtin.systemd_service: + name: swap.target + masked: true # kubelet fails even if ansible_swaptotal_mb = 0 - name: Check swap From 55b86a584d9353b65536f7531494a565a10fd8fc Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 3 Nov 2023 10:42:01 +0100 Subject: [PATCH 2/3] Unconditionally disable swap We only care to disable it (the "swapon" registered variable is not used anywhere else. This allows to get rid of the ignore_errors, since this was added because swapon.stdout does not exist in check_mode (see issue #6642). --- roles/kubernetes/preinstall/tasks/0010-swapoff.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml index 1ac69c06ec3..e7b4c3d86cf 100644 --- a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml +++ b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml @@ -4,21 +4,10 @@ name: swap.target masked: true -# kubelet fails even if ansible_swaptotal_mb = 0 -- name: Check swap - command: /sbin/swapon -s - register: swapon - changed_when: no - - name: Disable swap command: /sbin/swapoff -a - when: - - swapon.stdout - ignore_errors: "{{ ansible_check_mode }}" # noqa ignore-errors - name: Disable swapOnZram for Fedora command: touch /etc/systemd/zram-generator.conf when: - - swapon.stdout - ansible_distribution in ['Fedora'] - ignore_errors: "{{ ansible_check_mode }}" # noqa ignore-errors From 25bbfbd5d0a883ec93c5b9f600dbffc6c57b0ab0 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Fri, 3 Nov 2023 10:44:54 +0100 Subject: [PATCH 3/3] Don't explicitly disable swapOnZram We're already masking the swap.target, which would pull the zram unit, hence no need to handle zram-generator specifically. --- roles/kubernetes/preinstall/tasks/0010-swapoff.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml index e7b4c3d86cf..53bcf2d1218 100644 --- a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml +++ b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml @@ -6,8 +6,3 @@ - name: Disable swap command: /sbin/swapoff -a - -- name: Disable swapOnZram for Fedora - command: touch /etc/systemd/zram-generator.conf - when: - - ansible_distribution in ['Fedora']