Add swapfile to both hosts.

This commit is contained in:
Jim Hague 2024-04-20 07:58:57 +01:00
parent 756b121a2b
commit f7d02fdd20
2 changed files with 19 additions and 1 deletions

16
states/swapfile/init.sls Normal file
View File

@ -0,0 +1,16 @@
{% 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 }}
fallocate -l {{ size }}M {{ path }}
chmod 0600 {{ path }}
mkswap {{ path }}
- unless: bash -c '[[ $(($(stat -c %s {{ path }}) / 1024**2)) = {{ size }} ]]'
mount.swap:
- persist: true

View File

@ -1,9 +1,10 @@
base:
'*':
- common
'hedwig.lunch.org.uk':
- debian
- swapfile
- apache
- mariadb
- backup
@ -18,6 +19,7 @@ base:
'scabbers.lunch.org.uk':
- debian
- swapfile
- certificates
- apache
- backup