community.general.btrfs_subvolume 模块 – 管理 btrfs 子卷
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查是否已安装它,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定: community.general.btrfs_subvolume。
community.general 6.6.0 中的新增功能
概要
- 创建、更新和删除 btrfs 子卷和快照。 
参数
| 参数 | 注释 | 
|---|---|
| 允许模块临时挂载目标 btrfs 文件系统以验证当前状态并进行任何必要的更改。 选项 
 | |
| 包含在要定位的 btrfs 文件系统中的块设备。 当存在多个 btrfs 文件系统时,用于指定应定位哪个文件系统。 | |
| 分配给要定位的 btrfs 文件系统的描述性标签。 当存在多个 btrfs 文件系统时,用于指定应定位哪个文件系统。 | |
| 分配给要定位的 btrfs 文件系统的唯一标识符。 当存在多个 btrfs 文件系统时,用于指定应定位哪个文件系统。 | |
| 要定位的子卷/快照的名称。 | |
| 定义当请求的快照路径上已存在子卷时的行为的策略。 
 
 
 选项 
 | |
| 标识创建的快照的源子卷。 推断创建的子卷是快照。 | |
| 指示目标子卷的当前状态。 选项 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:部分 在某些情况下,它可能会错误地报告正在创建的中间子卷。挂载后,如果在子卷创建位置发现类似文件的目录,则跳过该操作。 | 可以在  | |
| 支持:不支持 | 处于 diff 模式时,将返回有关已更改内容(或可能需要在  | 
备注
注意
- 如果提供了任何或所有选项 - filesystem_device、- filesystem_label或- filesystem_uuid参数,则应存在匹配的 btrfs 文件系统。如果没有提供任何参数并且只有一个 btrfs 文件系统存在或只有一个 btrfs 文件系统已挂载,则将使用该文件系统;否则,模块将不执行任何操作并返回错误。
示例
- name: Create a @home subvolume under the root subvolume
  community.general.btrfs_subvolume:
    name: /@home
    filesystem_device: /dev/vda2
- name: Remove the @home subvolume if it exists
  community.general.btrfs_subvolume:
    name: /@home
    state: absent
    filesystem_device: /dev/vda2
- name: Create a snapshot of the root subvolume named @
  community.general.btrfs_subvolume:
    name: /@
    snapshot_source: /
    filesystem_device: /dev/vda2
- name: Create a snapshot of the root subvolume and make it the new default subvolume
  community.general.btrfs_subvolume:
    name: /@
    snapshot_source: /
    default: Yes
    filesystem_device: /dev/vda2
- name: Create a snapshot of the /@ subvolume and recursively creating intermediate subvolumes as required
  community.general.btrfs_subvolume:
    name: /@snapshots/@2022_06_09
    snapshot_source: /@
    recursive: True
    filesystem_device: /dev/vda2
- name: Remove the /@ subvolume and recursively delete child subvolumes as required
  community.general.btrfs_subvolume:
    name: /@snapshots/@2022_06_09
    snapshot_source: /@
    recursive: True
    filesystem_device: /dev/vda2
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 目标 btrfs 文件系统的最终状态摘要。 返回: 成功 | |
| 文件系统默认子卷的 ID。 返回:成功,且文件系统已挂载 示例:  | |
| 分配给文件系统的设备列表。 返回: 成功 示例:  | |
| 分配给文件系统的可选标签。 返回: 成功 示例:  | |
| 包含文件系统所有子卷元数据的字典列表。 返回:成功,且文件系统已挂载 | |
| 分配给子卷的标识符,在包含的文件系统中唯一。 返回: 成功 示例:  | |
| 子卷在目标主机上挂载的路径。 返回: 成功 示例:  | |
| 此子卷父级的标识符。 返回: 成功 示例:  | |
| 相对于 btrfs 文件系统根目录的子卷的完整路径。 返回: 成功 示例:  | |
| 分配给文件系统的唯一标识符。 返回: 成功 示例:  | |
| 列表,每个元素描述对目标 btrfs 文件系统进行的更改。 返回: 成功 | |
