Saltstack Official Linux Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4KB

  1. {%- from "linux/map.jinja" import storage with context %}
  2. {%- if storage.enabled %}
  3. {%- for swap_name, swap in storage.swap.iteritems() %}
  4. {%- if swap.enabled %}
  5. {%- if swap.engine == 'partition' %}
  6. linux_create_swap_partition_{{ swap.device }}:
  7. cmd.run:
  8. - name: 'mkswap {{ swap.device }}'
  9. - unless: file -L -s {{ swap.device }} | grep -q 'swap file'
  10. linux_set_swap_partition_{{ swap.device }}:
  11. cmd.run:
  12. - name: 'swapon {{ swap.device }}'
  13. - unless: grep $(readlink -f {{ swap.device }}) /proc/swaps
  14. - require:
  15. - cmd: linux_create_swap_partition_{{ swap.device }}
  16. {{ swap.device }}:
  17. mount.swap:
  18. - persist: True
  19. - require:
  20. - cmd: linux_set_swap_partition_{{ swap.device }}
  21. {%- elif swap.engine == 'file' %}
  22. linux_create_swap_file_{{ swap.device }}:
  23. cmd.run:
  24. - name: 'dd if=/dev/zero of={{ swap.device }} bs=1048576 count={{ swap.size }} && chmod 0600 {{ swap.device }}'
  25. - creates: {{ swap.device }}
  26. linux_set_swap_file_{{ swap.device }}:
  27. cmd.wait:
  28. - name: 'mkswap {{ swap.device }}'
  29. - watch:
  30. - cmd: linux_create_swap_file_{{ swap.device }}
  31. linux_set_swap_file_status_{{ swap.device }}:
  32. cmd.run:
  33. - name: 'swapon {{ swap.device }}'
  34. - unless: grep {{ swap.device }} /proc/swaps
  35. - require:
  36. - cmd: linux_set_swap_file_{{ swap.device }}
  37. {{ swap.device }}:
  38. mount.swap:
  39. - persist: True
  40. - require:
  41. - cmd: linux_set_swap_file_{{ swap.device }}
  42. {%- endif %}
  43. {%- endif %}
  44. {%- endfor %}
  45. {%- endif %}