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.

95 satır
2.3KB

  1. {%- from "linux/map.jinja" import storage with context %}
  2. {%- if storage.enabled %}
  3. {%- if storage.swap.enabled is not defined or storage.swap.enabled %}
  4. {%- for swap_name, swap in storage.swap.items() %}
  5. {%- if swap.enabled %}
  6. {%- if swap.engine == 'partition' %}
  7. linux_create_swap_partition_{{ swap.device }}:
  8. cmd.run:
  9. - name: 'mkswap {{ swap.device }}'
  10. - unless: file -L -s {{ swap.device }} | grep -q 'swap file'
  11. linux_set_swap_partition_{{ swap.device }}:
  12. cmd.run:
  13. - name: 'swapon {{ swap.device }}'
  14. - unless: grep $(readlink -f {{ swap.device }}) /proc/swaps
  15. - require:
  16. - cmd: linux_create_swap_partition_{{ swap.device }}
  17. {{ swap.device }}:
  18. mount.swap:
  19. - persist: True
  20. - require:
  21. - cmd: linux_set_swap_partition_{{ swap.device }}
  22. {%- elif swap.engine == 'file' %}
  23. linux_create_swap_file_{{ swap.device }}:
  24. cmd.run:
  25. - name: 'dd if=/dev/zero of={{ swap.device }} bs=1048576 count={{ swap.size }} && chmod 0600 {{ swap.device }}'
  26. - creates: {{ swap.device }}
  27. linux_set_swap_file_{{ swap.device }}:
  28. cmd.wait:
  29. - name: 'mkswap {{ swap.device }}'
  30. - watch:
  31. - cmd: linux_create_swap_file_{{ swap.device }}
  32. linux_set_swap_file_status_{{ swap.device }}:
  33. cmd.run:
  34. - name: 'swapon {{ swap.device }}'
  35. - unless: grep {{ swap.device }} /proc/swaps
  36. - require:
  37. - cmd: linux_set_swap_file_{{ swap.device }}
  38. {{ swap.device }}:
  39. mount.swap:
  40. - persist: True
  41. - require:
  42. - cmd: linux_set_swap_file_{{ swap.device }}
  43. {%- endif %}
  44. {%- else %}
  45. {{ swap.device }}:
  46. module.run:
  47. {%- if 'module.run' in salt['config.get']('use_superseded', default=[]) %}
  48. - mount.rm_fstab:
  49. - m_name: none
  50. - device: {{ swap.device }}
  51. {%- else %}
  52. - name: mount.rm_fstab
  53. - m_name: none
  54. - device: {{ swap.device }}
  55. {%- endif %}
  56. - onlyif: grep -q {{ swap.device }} /etc/fstab
  57. linux_disable_swap_{{ swap.engine }}_{{ swap.device }}:
  58. cmd.run:
  59. {%- if swap.engine == 'partition' %}
  60. - name: 'swapoff {{ swap.device }}'
  61. {%- elif swap.engine == 'file' %}
  62. - name: 'swapoff {{ swap.device }} && rm -f {{ swap.device }}'
  63. {%- endif %}
  64. - onlyif: file -L -s {{ swap.device }} | grep -q 'swap file'
  65. {%- endif %}
  66. {%- endfor %}
  67. {%- elif storage.swap.enabled is defined and not storage.swap.enabled %}
  68. linux_disable_swap:
  69. cmd.run:
  70. - name: 'swapoff -a'
  71. {%- endif %}
  72. {%- endif %}