Browse Source

Merge "Use unless to determine whether to create partition"

pull/118/head
Jakub Pavlik 7 years ago
parent
commit
3a033ecb81
1 changed files with 11 additions and 9 deletions
  1. +11
    -9
      linux/storage/disk.sls

+ 11
- 9
linux/storage/disk.sls View File

@@ -5,30 +5,32 @@ parted:
pkg.installed

{%- for disk_name, disk in storage.disk.iteritems() %}
{%- set disk_name = disk.name|default(disk_name) %}

{%- if disk.type is defined %}
create_disk_label:
module.run:
- name: partition.mklabel
- device: {{ disk.name|default(disk_name) }}
- label_type: {{ disk.get('type', 'gpt') }}
- unless: fdisk -l | grep {{ disk.get('type', 'gpt') }}
{%- endif %}
- device: {{ disk_name }}
- label_type: {{ disk.get('type', 'dos') }}
- unless: "fdisk -l {{ disk_name }} | grep -i 'Disklabel type: {{ disk.get('type', 'dos') }}'"
- require:
- pkg: parted

{% set end_size = 0 -%}

{%- for partition in disk.get('partitions', []) %}

{%- if not salt['partition.exists'](disk.get('name', disk_name)+'p'~loop.index) %}
create_partition_{{ disk.name|default(disk_name) }}_{{ loop.index }}:
create_partition_{{ disk_name }}_{{ loop.index }}:
module.run:
- name: partition.mkpart
- device: {{ disk.name|default(disk_name) }}
- device: {{ disk_name }}
- part_type: primary
- fs_type: {{ partition.type }}
- start: {{ end_size }}MB
- end: {{ end_size + partition.size }}MB
{%- endif %}
- unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }}"
- require:
- module: create_disk_label

{% set end_size = end_size + partition.size -%}


Loading…
Cancel
Save