rodzic
commit
b2eff892eb
6 zmienionych plików z 54 dodań i 23 usunięć
  1. +10
    -0
      tasks/debian.yml
  2. +8
    -0
      tasks/gdisk.yml
  3. +12
    -18
      tasks/main.yml
  4. +15
    -0
      templates/parted_args.j2
  5. +9
    -0
      templates/sgdisk_args.j2
  6. +0
    -5
      vars/main.yml

+ 10
- 0
tasks/debian.yml Wyświetl plik

@@ -0,0 +1,10 @@
---

- name: apt packages installed
apt:
pkg: "{{ item }}"
state: installed
with_items:
#- gdisk
- hdparm
- parted

+ 8
- 0
tasks/gdisk.yml Wyświetl plik

@@ -0,0 +1,8 @@
---

- name: write gpt partition table
command:
sgdisk
{{ lookup('template','sgdisk_args.j2') }}
with_items: "{{ hard_disks }}"
when: item.partition_table == "gpt"

+ 12
- 18
tasks/main.yml Wyświetl plik

@@ -1,30 +1,24 @@
---

- name: set default partitions
set_fact:
hard_disks: "{{ _hard_disks }}"
- setup:
gather_subset: "!all"

- name: clear all partition table informations from disks
- name: debian
include: debian.yml
when: ansible_os_family == "Debian"

#- include: gdisk.yml

- name: write partition table
command:
sgdisk
--clear
parted --script
{{ item.device }}
-- {{ lookup('template','parted_args.j2') }}
with_items: "{{ hard_disks }}"
- name: create new partition table information
command:
sgdisk
"--new={{ item.1.partnum }}:{{ item.1.start }}:{{ item.1.end }}"
"--change-name={{ item.1.partnum }}:{{ item.1.name }}"
"--typecode={{ item.1.partnum }}:{{ item.1.typecode }}"
{{ item.0.device }}
with_subelements:
- "{{ hard_disks }}"
- partitions

- name: sync
command: sync

- name: reread partition tables
command: hdparm -z {{ item.device }}
with_items: "{{ hard_disks }}"

+ 15
- 0
templates/parted_args.j2 Wyświetl plik

@@ -0,0 +1,15 @@
mklabel {{ item.label_type }}
{% for part in item.partitions %}
mkpart
{% if item.label_type == "msdos" or item.label_type == "dvh" %}
"{{ part.part_type }}"
{% endif %}
{% if part.fs_type is defined %}
"{{ part.fs_type }}"
{% endif %}
{% if part.name is defined %}
"{{ part.name }}
"{% endif %}
"{{ part.start }}"
"{{ part.end }}"
{% endfor %}

+ 9
- 0
templates/sgdisk_args.j2 Wyświetl plik

@@ -0,0 +1,9 @@
--clear
"--disk-guid={{ item.guid | default('R') }}"
{% for part in item.partitions %}
"--new={{ part.partnum }}:{{ part.start }}:{{ part.end }}"
"--change-name={{ part.partnum }}:{{ part.name }}"
"--typecode={{ part.partnum }}:{{ part.typecode }}"
"--partition-guid={{ part.partnum }}:{{ part.guid | default('R') }}"
{% endfor %}
{{ item.device }}

+ 0
- 5
vars/main.yml Wyświetl plik

@@ -1,5 +0,0 @@
_hard_disks: "{{ lookup('template','set_fact-hard_disks.j2') | from_yaml }}"

_hard_disk_default:
partition_label: "{{ default_partition_label }}"
partitions: "{{ default_partitions }}"

Ładowanie…
Anuluj
Zapisz