概述
This module creates, removes or resizes volume groups.
创建、删除卷组以及动态改变卷组大小。
常用模块
vg : The name of the volume group
要创建的卷组名称
pvs : List of comma-separated devices to use as physical devices in this volume group.
Required when creating or resizing volume group. The module will take care of running pvcreate if needed.
要加入到卷组中的物理卷列表
pesize : The size of the physical extent. `pesize’ must be a power of 2 of at least 1 sector (where the sector size is the largest sector size of the PVs currently used in the VG), or at least 128KiB. Since Ansible 2.6, pesize can be optionally suffixed by a UNIT (k/K/m/M/g/G), default unit is megabyte. [Default: 4]
指定pe大小,默认值是4M,默认单位是M。
state : Control if the volume group exists. (Choices: absent, present)[Default: present]
模块状态,absent代表删除,present代表新建,默认是present。
示例
案例1:创建卷组(vg.services)并且将物理卷sdb1加入到卷组中,指定pe大小为32M。
- name: Create a volume group on top of /dev/sdb1 with physical extent size = 32MBlvg:vg: vg.servicespvs: /dev/sdb1pesize: 32
指定PE的时候没有单位
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb1 pesize=32'
classroom | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true
}
[root@control ~]# ansible classroom -a 'vgdisplay vg.services'
classroom | CHANGED | rc=0 >>--- Volume group ---VG Name vg.servicesSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 1Act PV 1VG Size 992.00 MiBPE Size 32.00 MiBTotal PE 31Alloc PE / Size 0 / 0 Free PE / Size 31 / 992.00 MiBVG UUID LTzgWU-a8pz-fk4Z-BR3J-w58j-ib4s-bvuvQq
案例2:创建卷组(vg.services)并且将物理卷sdb2加入到卷组中,指定pe大小为128KiB。
- name: Create a volume group on top of /dev/sdb2 with physical extent size = 128KiBlvg:vg: vg.servicespvs: /dev/sdbpesize: 128K
指定PE的时候有单位
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb1 pesize=128K state=present'
classroom | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true
}[root@control ~]# ansible classroom -a 'pvdisplay'
classroom | CHANGED | rc=0 >>--- Physical volume ---PV Name /dev/sdb1VG Name vg.servicesPV Size 1023.00 MiB / not usable 0 Allocatable yes PE Size 128.00 KiBTotal PE 8176Free PE 8176Allocated PE 0
案例3:在案例1的基础上新增物理卷sdb2
name: Create or resize a volume group on top of /dev/sdb1 and /dev/sdb2.lvg:vg: vg.servicespvs: /dev/sdb1,/dev/sdb2
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb1'
classroom | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true
}
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb1,/dev/sdb2'
classroom | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true
}而不是ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb2'
不然的话,sdb1就移除vg了[root@control ~]# ansible classroom -a 'pvdisplay'
classroom | CHANGED | rc=0 >>--- Physical volume ---PV Name /dev/sdb1VG Name vg.servicesPV Size 1023.00 MiB / not usable 3.00 MiBAllocatable yes PE Size 4.00 MiBTotal PE 255Free PE 255Allocated PE 0PV UUID cIqSVO-9TfM-vOqz-A0oj-scoj-6su1-digL1B--- Physical volume ---PV Name /dev/sdb2VG Name vg.servicesPV Size 9.00 GiB / not usable 4.00 MiBAllocatable yes PE Size 4.00 MiBTotal PE 2303Free PE 2303Allocated PE 0PV UUID DPsWbd-CypK-8zSy-cej2-AbMp-JpBX-etrdEa
案例4:删除卷组
- name: Remove a volume group with name vg.serviceslvg:
vg: vg.services
state: absent
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services state=absent'
classroom | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": true
}[root@control ~]# ansible classroom -a 'vgscan'
classroom | CHANGED | rc=0 >>Reading all physical volumes. This may take a while...
NOTES
* 不能动态修改pe大小,只能删除重建vg的时候指定pe大小。* This module does not modify PE size for already present volume group.
在案例2的基础上尝试修改pe大小为4M
[root@control ~]# ansible classroom -m lvg -a 'vg=vg.services pvs=/dev/sdb1 pesize=4M state=present'
classroom | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false
}
pe大小没有变化
[root@control ~]# ansible classroom -a 'pvdisplay'
classroom | CHANGED | rc=0 >>--- Physical volume ---PV Name /dev/sdb1VG Name vg.servicesPV Size 1023.00 MiB / not usable 0 Allocatable yes PE Size 128.00 KiBTotal PE 8176Free PE 8176Allocated PE 0PV UUID fbRiY1-P1CR-Kl3C-6cjp-Jy8m-3ehi-ydKduh