ansible常用模块之 -- lvol模块 – 配置LVM逻辑卷
lvol模块 – 配置LVM逻辑卷
一、摘要
- 该模块创建、删除或调整逻辑卷的大小。
二、参数
参数 | 选项/默认值 | 描述 |
---|---|---|
active boolean | · yes ← · no | 卷是否处于激活状态且对主机可见。 |
force boolean | · no ← · yes | 卷的收缩或删除操作需要此开关。确保文件系统不会被错误损坏/破坏 |
lv | 逻辑卷的名称。 | |
opts | 传递给lvcreate命令的自由形式选项。 | |
pvs | 物理卷的逗号分隔列表(例如/dev/sda,/dev/sdb)。 | |
resizefs boolean | · no ← · yes | 与逻辑卷一起调整底层文件系统的大小 |
shrink boolean | · yes ← · no | 如果当前尺寸大于要求的尺寸,则收缩。 |
size | 逻辑卷的大小,根据lvcreate(8) --size,默认情况下以兆为单位,或可选使用[bBsSkKmMgGtTpPeE]单位之一;或者根据lvcreate(8) --extent作为[VG | |
snapshot | 快照卷的名称 | |
state | · present ← · absent | 控件是否存在逻辑卷。如果 present 且卷不存在,则需要使用 size 选项。 |
thinpool | 精简池卷名称。创建精简卷时,需要指定精简池卷名称。 | |
vg | 逻辑卷所在的卷组。 |
三、示例
# 创建512m的逻辑卷
- name: Create a logical volume of 512m
lvol:
vg: firefly
lv: test
size: 512
# 使用/dev/sda和/dev/sdb创建512m的逻辑卷
- name: Create a logical volume of 512m with disks /dev/sda and /dev/sdb
lvol:
vg: firefly
lv: test
size: 512
pvs: /dev/sda,/dev/sdb
# 创建缓存池逻辑卷
- name: Create cache pool logical volume
lvol:
vg: firefly
lv: lvcache
size: 512m
opts: --type cache-pool
# 创建512g的逻辑卷。
- name: Create a logical volume of 512g.
lvol:
vg: firefly
lv: test
size: 512g
# 创建一个逻辑卷,大小为卷组中所有剩余空间的大小
- name: Create a logical volume the size of all remaining space in the volume group
lvol:
vg: firefly
lv: test
size: 100%FREE
# 创建具有特殊选项的逻辑卷
- name: Create a logical volume with special options
lvol:
vg: firefly
lv: test
size: 512g
opts: -r 16
# 将逻辑卷扩展到1024m。
- name: Extend the logical volume to 1024m.
lvol:
vg: firefly
lv: test
size: 1024
# 扩展逻辑卷以占用卷组中所有剩余空间
- name: Extend the logical volume to consume all remaining space in the volume group
lvol:
vg: firefly
lv: test
size: +100%FREE
# 扩展逻辑卷以占用pv的所有剩余空间,并调整底层文件系统的大小
- name: Extend the logical volume to take all remaining space of the PVs and resize the underlying filesystem
lvol:
vg: firefly
lv: test
size: 100%PVS
resizefs: true
# 将逻辑卷大小调整为VG的%
- name: Resize the logical volume to % of VG
lvol:
vg: firefly
lv: test
size: 80%VG
force: yes
# 将逻辑卷缩小到512m
- name: Reduce the logical volume to 512m
lvol:
vg: firefly
lv: test
size: 512
force: yes
# 将逻辑卷设置为512m,如果小于当前大小,请不要尝试收缩
- name: Set the logical volume to 512m and do not try to shrink if size is lower than current one
lvol:
vg: firefly
lv: test
size: 512
shrink: no
# 删除逻辑卷。
- name: Remove the logical volume.
lvol:
vg: firefly
lv: test
state: absent
force: yes
# 为测试逻辑卷创建快照卷。
- name: Create a snapshot volume of the test logical volume.
lvol:
vg: firefly
lv: test
snapshot: snap1
size: 100m
# 取消激活逻辑卷
- name: Deactivate a logical volume
lvol:
vg: firefly
lv: test
active: false
# 创建去激活的逻辑卷
- name: Create a deactivated logical volume
lvol:
vg: firefly
lv: test
size: 512g
active: false
# 创建512g的精简池
- name: Create a thin pool of 512g
lvol:
vg: firefly
thinpool: testpool
size: 512g
# 创建128g的精简卷
- name: Create a thin volume of 128g
lvol:
vg: firefly
lv: test
thinpool: testpool
size: 128g
官方文档:https://docs.ansible.com/ansible/2.9/modules/lvol_module.html#lvol-module