ansible:使用 parted 模块创建 16 个分区时出错

ansible: Error creating 16 partitions using parted module

我正在尝试使用 ansible 从 4TB 块设备创建 16 个分区。我正在使用分离模块:https://docs.ansible.com/ansible/latest/modules/parted_module.html#examples

根据 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

根据我的阅读,如果我需要创建很多分区,我需要创建一个扩展分区(?)和 GPT 分区 table。 GPT 分区 table 的原因是扩展分区将大于 2TiB。创建扩展分区后,我可以创建 16 个逻辑分区。 (我认为我的假设是正确的。)

这是我创建的剧本,但不幸的是我遇到了错误运行。

---
- 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

当我 运行 它时,我收到以下错误(我 运行 通过 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": ""
}

我不知道哪里出了问题。我尝试了无数不同的东西,但似乎没有任何效果。任何帮助将不胜感激。

我能够使用这个剧本创建 16 个分区:

---
- name: Create 16 (= 4096 / 256) partitions
  parted:
    device: /dev/sdd
    number: "{{ (item | int | abs) + 1 }}"
    label: gpt
    name: "disk_{{ (item | int | abs) + 1 }}"
    part_start: "{{ (item | int | abs) * 256 }}GB"
    part_end: "{{ (item | int | abs) * 256 + 256 }}GB"
    unit: GB
    state: present
  with_sequence: start=0 count=16

我使用百分比来完成此操作,有 16 个相等的分区,我使用了与@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

`

注意 100/16 = 6.25