part_start 分割起點預設是 0% 碟碟最前端,另一參數 part_end 分割終點預設是 100% 硬碟最後端。
ceuser@deyu:~/ansible_pb$ ansible-doc parted | grep LVM -A6
- name: Create a new primary partition for LVM
community.general.parted:
device: /dev/sdb
number: 2
flags: [ lvm ]
state: present
part_start: 1GiB
ceuser@deyu:~/ansible_pb$ ansible balancers -m shell -a "lsblk" kvm15 | CHANGED | rc=0 >> NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS vda 252:0 0 6G 0 disk ├─vda1 252:1 0 1M 0 part ├─vda2 252:2 0 400M 0 part /boot └─vda3 252:3 0 3.4G 0 part ├─vg_kvm15-root 253:0 0 3.3G 0 lvm / └─vg_kvm15-swap 253:1 0 96M 0 lvm [SWAP] vdb 252:16 0 2.5G 0 disk vdc 252:32 0 1.5G 0 disk
ceuser@deyu:~/ansible_pb$ vi partvg.yml
ceuser@deyu:~/ansible_pb$ cat partvg.yml
---
- hosts: balancers
tasks:
- name: Create a new primary partition with a size of 1.2GiB
community.general.parted:
device: /dev/vdb
number: 1
state: present
part_end: 1.2GiB
fs_type: ext4
ceuser@deyu:~/ansible_pb$ ansible-playbook partvg.yml PLAY [balancers] *************************************************************** TASK [Gathering Facts] ********************************************************* ok: [kvm15] TASK [Create a new primary partition with a size of 1.2GiB] ********************** changed: [kvm15] PLAY RECAP ********************************************************************* kvm15 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ceuser@deyu:~/ansible_pb$ ansible balancers -m shell -a "fdisk -l /dev/vdb" kvm15 | CHANGED | rc=0 >> Disk /dev/vdb: 2.5 GiB, 2684354560 bytes, 5242880 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xce6507ef Device Boot Start End Sectors Size Id Type /dev/vdb1 1 2516581 2516581 1.2G 83 Linux