Ubuntu – How to enable swap with salt stack

saltstackswapUbuntu

How can I create and enable permanent 1GB swap file with salt stack that will work after reboot? salt.states.mount.swap does not allow to define swap size. Furthermore I need to define swappiness. Currently I do it with echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Best Answer

I currently use this in production, works for me.

community_swap_file:
  cmd.run:
    - name: |
        [ -f /.swapfile ] || dd if=/dev/zero of=/.swapfile bs=1M count=2048
        chmod 0600 /.swapfile
        mkswap /.swapfile
        echo '/.swapfile      none      swap     sw       0       0' >> /etc/fstab
        swapon -a
    - unless: file /.swapfile 2>&1 | grep -q "Linux/i386 swap"
Related Topic