From 2e8b72e27843e9cf70e9c8fe048e23c80ef39976 Mon Sep 17 00:00:00 2001 From: Kay Yan Date: Tue, 9 Jan 2024 00:38:14 +0800 Subject: [PATCH] fix disable swap in centos (#10751) --- .../preinstall/tasks/0010-swapoff.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml index 53bcf2d12..45474c844 100644 --- a/roles/kubernetes/preinstall/tasks/0010-swapoff.yml +++ b/roles/kubernetes/preinstall/tasks/0010-swapoff.yml @@ -1,4 +1,22 @@ --- +- name: Check if /etc/fstab exists + stat: + path: "/etc/fstab" + get_attributes: no + get_checksum: no + get_mime: no + register: fstab_file + +- name: Remove swapfile from /etc/fstab + ansible.posix.mount: + name: "{{ item }}" + fstype: swap + state: absent + loop: + - swap + - none + when: fstab_file.stat.exists + - name: Mask swap.target (persist swapoff) ansible.builtin.systemd_service: name: swap.target