Saltstack Official Linux Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

99 行
2.6KB

  1. {%- from "linux/map.jinja" import storage with context %}
  2. {%- if storage.enabled %}
  3. parted:
  4. pkg.installed
  5. xfsprogs:
  6. pkg.installed
  7. {%- for disk_name, disk in storage.disk.items() %}
  8. {%- set disk_name = disk.name|default(disk_name) %}
  9. create_disk_label_{{ disk_name }}:
  10. module.run:
  11. {%- if 'module.run' in salt['config.get']('use_superseded', default=[]) %}
  12. - partition.mklabel:
  13. - device: {{ disk_name }}
  14. - label_type: {{ disk.get('type', 'dos') }}
  15. {%- else %}
  16. - name: partition.mklabel
  17. - device: {{ disk_name }}
  18. - label_type: {{ disk.get('type', 'dos') }}
  19. {%- endif %}
  20. - unless: "fdisk -l {{ disk_name }} | grep -i 'Disklabel type: {{ disk.get('type', 'dos') }}'"
  21. - require:
  22. - pkg: parted
  23. {% set end_size = 0 -%}
  24. {% if disk.get('startsector', None) %}
  25. {% set end_size = disk.get('startsector')|int %}
  26. {% endif %}
  27. {%- for partition in disk.get('partitions', []) %}
  28. create_partition_{{ disk_name }}_{{ loop.index }}:
  29. module.run:
  30. {%- if 'module.run' in salt['config.get']('use_superseded', default=[]) %}
  31. - partition.mkpart:
  32. - device: {{ disk_name }}
  33. - part_type: primary
  34. {%- if partition.type is defined %}
  35. - fs_type: {{ partition.type }}
  36. {%- endif %}
  37. - start: {{ end_size }}MB
  38. - end: {{ end_size + partition.size }}MB
  39. {%- else %}
  40. - name: partition.mkpart
  41. - device: {{ disk_name }}
  42. - part_type: primary
  43. {%- if partition.type is defined %}
  44. - fs_type: {{ partition.type }}
  45. {%- endif %}
  46. - start: {{ end_size }}MB
  47. - end: {{ end_size + partition.size }}MB
  48. {%- endif %}
  49. - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }}"
  50. - require:
  51. - module: create_disk_label_{{ disk_name }}
  52. - pkg: xfsprogs
  53. {% set end_size = end_size + partition.size -%}
  54. {%- endfor %}
  55. probe_partions_{{ disk_name }}:
  56. module.run:
  57. {%- if 'module.run' in salt['config.get']('use_superseded', default=[]) %}
  58. - partition.probe:
  59. - device: {{ disk_name }}
  60. {%- else %}
  61. - name: partition.probe
  62. - device: {{ disk_name }}
  63. {%- endif %}
  64. {%- for partition in disk.get('partitions', []) %}
  65. {%- if partition.get('mkfs') and partition.type == "xfs" %}
  66. mkfs_partition_{{ disk_name }}_{{ loop.index }}:
  67. module.run:
  68. {%- if 'module.run' in salt['config.get']('use_superseded', default=[]) %}
  69. - xfs.mkfs:
  70. - device: {{ disk_name }}{{ loop.index }}
  71. {%- else %}
  72. - name: xfs.mkfs
  73. - device: {{ disk_name }}{{ loop.index }}
  74. {%- endif %}
  75. - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }} | grep xfs"
  76. - require:
  77. - module: create_partition_{{ disk_name }}_{{ loop.index }}
  78. {%- endif %}
  79. {%- endfor %}
  80. {%- endfor %}
  81. {%- endif %}