Saltstack Official Linux Formula
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 %}