2024-04-20 07:58:57 +01:00
|
|
|
{% set swapfile = salt['pillar.get']('swapfile', {}) %}
|
|
|
|
{% set size = swapfile.get('size', grains["mem_total"]) %}
|
|
|
|
{% set path = swapfile.get('path', '/swapfile') %}
|
|
|
|
|
|
|
|
{{ path }}:
|
|
|
|
cmd.run:
|
|
|
|
- name: |
|
|
|
|
swapon --show=NAME --noheadings | grep -q "^{{ path }}$" && swapoff {{ path }}
|
|
|
|
rm -f {{ path }}
|
2024-04-20 08:12:22 +01:00
|
|
|
dd if=/dev/zero of={{ path }} bs=1M count={{ size }}
|
2024-04-20 07:58:57 +01:00
|
|
|
chmod 0600 {{ path }}
|
|
|
|
mkswap {{ path }}
|
|
|
|
- unless: bash -c '[[ $(($(stat -c %s {{ path }}) / 1024**2)) = {{ size }} ]]'
|
|
|
|
|
|
|
|
mount.swap:
|
|
|
|
- persist: true
|