Browse Source

Use unless to determine whether to create partition

Change-Id: I1c35eb045a46b95f75c7101567d4c4f340b787ab
pull/118/head
Filip Pytloun 7 years ago
parent
commit
71abe455fb
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