I'm trying to create 16 partitions from a 4TB block device with ansible. I'm using the parted module: https://docs.ansible.com/ansible/latest/modules/parted_module.html#examples
I verified the device is connected and the kernel sees it, according to dmesg:
[root@ZUSE1DLMSORDB1 YoCp19h2cn]# dmesg | grep sdd
[ 5.837562] sd 5:0:0:11: [sdd] 8589934592 512-byte logical blocks: (4.39 TB/4.00 TiB)
[ 5.837564] sd 5:0:0:11: [sdd] 4096-byte physical blocks
[ 5.858252] sd 5:0:0:11: [sdd] Write Protect is off
[ 5.858254] sd 5:0:0:11: [sdd] Mode Sense: 0f 00 10 00
[ 5.858449] sd 5:0:0:11: [sdd] Write cache: disabled, read cache: enabled, supports DPO and FUA
[ 5.911159] sdd: sdd1
[ 5.930018] sd 5:0:0:11: [sdd] Attached SCSI disk
According to what I have read, if I need to create a lot of partitions I need to create an extended partition (?) with GPT partition table. The reason for the GPT partition table is the extended partition will be large than 2TiB. After creating the extended partition I can then create 16 logical partitions. (I think my assumptions are correct.)
Here is the playbook I created to, but unfortunately I'm getting errors running it.
---
- name: Create a new extended (to hold all the logical partitions) partition
parted:
device: /dev/sdd
number: 1
part_type: extended
label: gpt
name: UberPartition
state: present
- name: Create 16 (= 4096 / 256) logical partitions
parted:
device: /dev/sdd1
number: "{{ item }}"
part_type: logical
part_end: 16%
unit: GB
state: present
with_sequence: count=16
When I run it I get the following errors (I'm running the playbook via AWX):
{
"_ansible_parsed": true,
"changed": false,
"_ansible_item_label": "2",
"err": "/sbin/parted: invalid token: logical\nError: Expecting a partition type.\n",
"_ansible_no_log": false,
"_ansible_item_result": true,
"invocation": {
"module_args": {
"part_start": "0%",
"part_end": "16%",
"name": "disk_2",
"align": "optimal",
"number": 2,
"label": "msdos",
"state": "present",
"part_type": "logical",
"flags": null,
"device": "/dev/sdd",
"unit": "GB"
}
},
"item": "2",
"rc": 1,
"msg": "Error while running parted script: /sbin/parted -s -m -a optimal /dev/sdd -- unit GB mkpart logical 0% 16%",
"_ansible_ignore_errors": null,
"out": ""
}
I can't figure out what is wrong. I tried a myriad different things and nothing seem to be working. Any help would be greatly appreciated.
I did this using percentage, with 16 equal partitions, I used the same playbook as described by @Gerb.
`
- name: Create 16 equal partition
parted:
device: /dev/sdd
number: "{{ (item | int | abs) + 1 }}"
label: linx
flags: [ lvm ]
name: "disk{{ (item | int | abs) + 1 }}"
part_start: "{{ (item | int | abs) * 6.25 }}%"
part_end: "{{ (item | int | abs) * 6.25 + 6.25 }}%"
unit: "%"
state: present
with_sequence: start=0 count=16
`
Note that 100/16 = 6.25