community.general.lvol 模块 – 配置 LVM 逻辑卷

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定:community.general.lvol

概要

  • 此模块创建、删除或调整逻辑卷的大小。

参数

参数

注释

active

布尔值

卷是否处于活动状态且对主机可见。

选择

  • false

  • true ← (默认)

force

布尔值

卷的收缩或删除操作需要此开关。确保文件系统永远不会因错误而损坏/销毁。

选择

  • false ← (默认)

  • true

lv

字符串

逻辑卷的名称。

opts

字符串

要传递给 lvcreate 命令的自由格式选项。

pvs

列表 / 元素=字符串

物理卷列表(例如 /dev/sda, /dev/sdb)。

resizefs

布尔值

调整底层文件系统以及逻辑卷的大小。

支持 ext2ext3ext4reiserfsXFS 文件系统。尝试调整其他文件系统类型的大小将失败。

选择

  • false ← (默认)

  • true

shrink

布尔值

如果当前大小高于请求的大小,则缩小。

选择

  • false

  • true ← (默认)

size

字符串

逻辑卷的大小,根据 lvcreate(8) –size,默认单位为兆字节,或者可以选择使用 [bBsSkKmMgGtTpPeE] 单位之一;或者根据 lvcreate(8) –extents,以 [VG|PVS|FREE|ORIGIN] 的百分比表示;浮点值必须以数字开头。

调整大小时,除了指定绝对大小外,您还可以根据 lvextend(8)|lvreduce(8) --size,指定使用前缀 + 扩展逻辑卷的量,或使用前缀 - 减少逻辑卷的量。

在 community.general 3.0.0 之前不支持使用 +- 进行调整大小。

请注意,当使用 +- 或 FREE 的百分比时,该模块是非幂等的。

snapshot

字符串

要配置的快照卷的名称。创建快照卷时,lv 参数指定源卷。

state

字符串

控制逻辑卷是否存在。如果为 present 并且该卷尚不存在,则需要 size 选项。

选择

  • "absent"

  • "present" ← (默认)

thinpool

字符串

精简池卷名称。当您要创建精简配置卷时,请指定精简池卷名称。

vg

字符串 / 必需

此逻辑卷所属的卷组。

属性

属性

支持

描述

check_mode

支持: 完整

可以在 check_mode 中运行并返回更改的状态预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,将返回有关已更改(或可能需要在 check_mode 中更改)的详细信息。

注释

注意

  • 您必须指定 lv(当管理逻辑卷的状态时)或 thinpool(当管理精简配置卷时)。

示例

- name: Create a logical volume of 512m
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512

- name: Create a logical volume of 512m with disks /dev/sda and /dev/sdb
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512
    pvs:
      - /dev/sda
      - /dev/sdb

- name: Create cache pool logical volume
  community.general.lvol:
    vg: firefly
    lv: lvcache
    size: 512m
    opts: --type cache-pool

- name: Create a logical volume of 512g.
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512g

- name: Create a logical volume the size of all remaining space in the volume group
  community.general.lvol:
    vg: firefly
    lv: test
    size: 100%FREE

- name: Create a logical volume with special options
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512g
    opts: -r 16

- name: Extend the logical volume to 1024m.
  community.general.lvol:
    vg: firefly
    lv: test
    size: 1024

- name: Extend the logical volume to consume all remaining space in the volume group
  community.general.lvol:
    vg: firefly
    lv: test
    size: +100%FREE

- name: Extend the logical volume by given space
  community.general.lvol:
    vg: firefly
    lv: test
    size: +512M

- name: Extend the logical volume to take all remaining space of the PVs and resize the underlying filesystem
  community.general.lvol:
    vg: firefly
    lv: test
    size: 100%PVS
    resizefs: true

- name: Resize the logical volume to % of VG
  community.general.lvol:
    vg: firefly
    lv: test
    size: 80%VG
    force: true

- name: Reduce the logical volume to 512m
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512
    force: true

- name: Reduce the logical volume by given space
  community.general.lvol:
    vg: firefly
    lv: test
    size: -512M
    force: true

- name: Set the logical volume to 512m and do not try to shrink if size is lower than current one
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512
    shrink: false

- name: Remove the logical volume.
  community.general.lvol:
    vg: firefly
    lv: test
    state: absent
    force: true

- name: Create a snapshot volume of the test logical volume.
  community.general.lvol:
    vg: firefly
    lv: test
    snapshot: snap1
    size: 100m

- name: Deactivate a logical volume
  community.general.lvol:
    vg: firefly
    lv: test
    active: false

- name: Create a deactivated logical volume
  community.general.lvol:
    vg: firefly
    lv: test
    size: 512g
    active: false

- name: Create a thin pool of 512g
  community.general.lvol:
    vg: firefly
    thinpool: testpool
    size: 512g

- name: Create a thin volume of 128g
  community.general.lvol:
    vg: firefly
    lv: test
    thinpool: testpool
    size: 128g

作者

  • Jeroen Hoekx (@jhoekx)

  • Alexander Bulimov (@abulimov)

  • Raoul Baudach (@unkaputtbar112)

  • Ziga Kern (@zigaSRC)