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.

72 lines
1.8KB

  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. - name: partition.mklabel
  12. - device: {{ disk_name }}
  13. - label_type: {{ disk.get('type', 'dos') }}
  14. - unless: "fdisk -l {{ disk_name }} | grep -i 'Disklabel type: {{ disk.get('type', 'dos') }}'"
  15. - require:
  16. - pkg: parted
  17. {% set end_size = 0 -%}
  18. {% if disk.get('startsector', None) %}
  19. {% set end_size = disk.get('startsector')|int %}
  20. {% endif %}
  21. {%- for partition in disk.get('partitions', []) %}
  22. create_partition_{{ disk_name }}_{{ loop.index }}:
  23. module.run:
  24. - name: partition.mkpart
  25. - device: {{ disk_name }}
  26. - part_type: primary
  27. {%- if partition.type is defined %}
  28. - fs_type: {{ partition.type }}
  29. {%- endif %}
  30. - start: {{ end_size }}MB
  31. - end: {{ end_size + partition.size }}MB
  32. - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }}"
  33. - require:
  34. - module: create_disk_label_{{ disk_name }}
  35. - pkg: xfsprogs
  36. {% set end_size = end_size + partition.size -%}
  37. {%- endfor %}
  38. probe_partions_{{ disk_name }}:
  39. module.run:
  40. - name: partition.probe
  41. - device: {{ disk_name }}
  42. {%- for partition in disk.get('partitions', []) %}
  43. {%- if partition.get('mkfs') and partition.type == "xfs" %}
  44. mkfs_partition_{{ disk_name }}_{{ loop.index }}:
  45. module.run:
  46. - name: xfs.mkfs
  47. - device: {{ disk_name }}{{ loop.index }}
  48. - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }} | grep xfs"
  49. - require:
  50. - module: create_partition_{{ disk_name }}_{{ loop.index }}
  51. {%- endif %}
  52. {%- endfor %}
  53. {%- endfor %}
  54. {%- endif %}