--- - name: set default partitions set_fact: hard_disks: "{{ _hard_disks }}" - name: clear all partition table informations from disks command: sgdisk --clear {{ item.device }} 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 }}"