From b2eff892ebf501c4185abef4b7da58039b215bce Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Tue, 20 Dec 2016 05:36:08 +0000 Subject: [PATCH] current --- tasks/debian.yml | 10 ++++++++++ tasks/gdisk.yml | 8 ++++++++ tasks/main.yml | 30 ++++++++++++------------------ templates/parted_args.j2 | 15 +++++++++++++++ templates/sgdisk_args.j2 | 9 +++++++++ vars/main.yml | 5 ----- 6 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 tasks/debian.yml create mode 100644 tasks/gdisk.yml create mode 100644 templates/parted_args.j2 create mode 100644 templates/sgdisk_args.j2 diff --git a/tasks/debian.yml b/tasks/debian.yml new file mode 100644 index 0000000..01d4f0b --- /dev/null +++ b/tasks/debian.yml @@ -0,0 +1,10 @@ +--- + +- name: apt packages installed + apt: + pkg: "{{ item }}" + state: installed + with_items: + #- gdisk + - hdparm + - parted \ No newline at end of file diff --git a/tasks/gdisk.yml b/tasks/gdisk.yml new file mode 100644 index 0000000..7798a0f --- /dev/null +++ b/tasks/gdisk.yml @@ -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" diff --git a/tasks/main.yml b/tasks/main.yml index 4140428..ebde88b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 }}" diff --git a/templates/parted_args.j2 b/templates/parted_args.j2 new file mode 100644 index 0000000..bc25938 --- /dev/null +++ b/templates/parted_args.j2 @@ -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 %} diff --git a/templates/sgdisk_args.j2 b/templates/sgdisk_args.j2 new file mode 100644 index 0000000..d9ae376 --- /dev/null +++ b/templates/sgdisk_args.j2 @@ -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 }} diff --git a/vars/main.yml b/vars/main.yml index 2af612b..e69de29 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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 }}"