From 1c3b58a67168ce6e9be72f2ecf8ace10df9f7512 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sun, 11 Aug 2019 09:51:37 +0200 Subject: [PATCH] copr: backend: detect swap is enabled before disabling it I am not opening a question whether disabling swap is a good idea, I'm just want to make the execution of the playbook idempotent. --- roles/copr/backend/tasks/main.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/roles/copr/backend/tasks/main.yml b/roles/copr/backend/tasks/main.yml index 5ac74a86c0..9d550dcc15 100644 --- a/roles/copr/backend/tasks/main.yml +++ b/roles/copr/backend/tasks/main.yml @@ -247,7 +247,12 @@ fstype: swap state: absent +- name: detect if swap is enabled + shell: test -n "$(swapon -s)" + register: swap_enabled + changed_when: false + failed_when: false + - name: disable swap so that OOM killer can do his job - command: "{{ item }}" - with_items: - - swapoff -a + command: swapoff -a + when: swap_enabled.rc != 0