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.

78 lines
1.9KB

  1. {%- from "linux/map.jinja" import storage with context %}
  2. {%- if storage.enabled %}
  3. linux_lvm_pkgs:
  4. pkg.installed:
  5. - pkgs: {{ storage.lvm_pkgs | json }}
  6. /etc/lvm/lvm.conf:
  7. file.managed:
  8. - source: salt://linux/files/lvm.conf
  9. - template: jinja
  10. - require:
  11. - pkg: linux_lvm_pkgs
  12. lvm_services:
  13. service.running:
  14. - enable: true
  15. - names: {{ storage.lvm_services }}
  16. - require:
  17. - file: /etc/lvm/lvm.conf
  18. - watch:
  19. - file: /etc/lvm/lvm.conf
  20. {%- for vgname, vg in storage.lvm.items() %}
  21. {%- if vg.get('enabled', True) %}
  22. {%- for dev in vg.devices %}
  23. lvm_{{ vg.get('name', vgname) }}_pv_{{ dev }}:
  24. lvm.pv_present:
  25. - name: {{ dev }}
  26. - require:
  27. - pkg: linux_lvm_pkgs
  28. - file: /etc/lvm/lvm.conf
  29. - service: lvm_services
  30. - require_in:
  31. - lvm: lvm_vg_{{ vg.get('name', vgname) }}
  32. {%- endfor %}
  33. lvm_vg_{{ vg.get('name', vgname) }}:
  34. lvm.vg_present:
  35. - name: {{ vg.get('name', vgname) }}
  36. - devices: {{ vg.devices|join(',') }}
  37. {%- for lvname, volume in vg.get('volume', {}).items() %}
  38. lvm_{{ vg.get('name', vgname) }}_lv_{{ volume.get('name', lvname) }}:
  39. lvm.lv_present:
  40. - order: 1
  41. - name: {{ volume.get('name', lvname) }}
  42. - vgname: {{ vg.get('name', vgname) }}
  43. - size: {{ volume.size }}
  44. {%- if (volume.force is defined and volume.force is sameas true) or
  45. (volume.get('name', lvname) not in grains.lvm[vg.get('name', vgname)]) %}
  46. - force: True
  47. {%- else %}
  48. - force: False
  49. {%- endif %}
  50. - require:
  51. - lvm: lvm_vg_{{ vg.get('name', vgname) }}
  52. {%- if (volume.mount is defined) and
  53. (volume.get('name', lvname) not in grains.lvm[vg.get('name', vgname)]) %}
  54. - require_in:
  55. - mount: {{ volume.mount.path }}
  56. {%- if not volume.mount.get('file_system', None) in ['nfs', 'nfs4', 'cifs', 'tmpfs', None] %}
  57. - cmd: mkfs_{{ volume.mount.device}}
  58. {%- endif %}
  59. {%- endif %}
  60. {%- endfor %}
  61. {%- endif %}
  62. {%- endfor %}
  63. {%- endif %}