From 20c41ee9fecfc92032b19825e4452a231d996d81 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 14 Aug 2024 14:07:06 -0500 Subject: [PATCH 1/2] feat: require swap to run before datadoge --- pillar/prod/swapfile.sls | 6 +++--- salt/base/swap.sls | 22 +++++++++++----------- salt/datadog/init.sls | 1 + 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pillar/prod/swapfile.sls b/pillar/prod/swapfile.sls index 465c71c4..77a7130f 100644 --- a/pillar/prod/swapfile.sls +++ b/pillar/prod/swapfile.sls @@ -1,3 +1,3 @@ -swapfile: - size: 1024 - path: /swapfile +swap_file: + swap_size: 1024 + swap_path: /swapfile diff --git a/salt/base/swap.sls b/salt/base/swap.sls index 262c1393..91896c57 100644 --- a/salt/base/swap.sls +++ b/salt/base/swap.sls @@ -1,17 +1,17 @@ -{% set swapfile = salt["pillar.get"]("swapfile", {}) %} -{% set size = swapfile.get("size", "1024") %} -{% set path = swapfile.get("path") %} +{% set swap_file = salt["pillar.get"]("swap_file", {}) %} +{% set swap_size = swap_file.get("swap_size", "1024") %} +{% set swap_path = swap_file.get("swap_path") %} -{% if path %} -{{ path }}: +{% if swap_path %} +{{ swap_path }}: cmd.run: - name: | - swapon --show=NAME --noheadings | grep -q "^{{ path }}$" && swapoff {{ path }} - rm -f {{ path }} - fallocate -l {{ size }}M {{ path }} - chmod 0600 {{ path }} - mkswap {{ path }} - - unless: bash -c "[[ $(($(stat -c %s {{ path }}) / 1024**2)) = {{ size }} ]]" + swapon --show=NAME --noheadings | grep -q "^{{ swap_path }}$" && swapoff {{ swap_path }} + rm -f {{ swap_path }} + fallocate -l {{ swap_size }}M {{ swap_path }} + chmod 0600 {{ swap_path }} + mkswap {{ swap_path }} + - unless: bash -c "[[ $(($(stat -c %s {{ swap_path }}) / 1024**2)) = {{ swap_size }} ]]" mount.swap: - persist: true diff --git a/salt/datadog/init.sls b/salt/datadog/init.sls index 19aa38a1..58514be7 100644 --- a/salt/datadog/init.sls +++ b/salt/datadog/init.sls @@ -36,6 +36,7 @@ datadog-agent: - installed - require: - pkgrepo: datadog_repo + - mount: {{ swap_path }} service: - running - enable: True From d2c1fd92ee8d582954154a1b811b71204e5de650 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Wed, 14 Aug 2024 14:11:08 -0500 Subject: [PATCH 2/2] fix: check for swap path existance first --- salt/datadog/init.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/datadog/init.sls b/salt/datadog/init.sls index 58514be7..41d7d691 100644 --- a/salt/datadog/init.sls +++ b/salt/datadog/init.sls @@ -36,7 +36,7 @@ datadog-agent: - installed - require: - pkgrepo: datadog_repo - - mount: {{ swap_path }} + - mount: {% if swap_path %}{{ swap_path }}{% endif %} service: - running - enable: True