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

时间:2019-08-09 16:27:41

标签: ansible parted

我正在尝试使用ansible从4TB块设备创建16个分区。我正在使用parted模块: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分区表创建扩展分区(?)。 GPT分区表的原因是扩展分区将大于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": ""
}

我不知道出什么问题了。我尝试了无数种不同的方法,但似乎没有任何效果。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

我可以使用此剧本创建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

答案 1 :(得分:0)

我使用百分比进行操作,具有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