community.general.btrfs_subvolume (8.5.0) — module

Manage btrfs subvolumes

| "added in version" 6.6.0 of community.general"

Authors: Gregory Furlong (@gnfzdz)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Creates, updates and deletes btrfs subvolumes and snapshots.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- name: Create a @home subvolume under the root subvolume
  community.general.btrfs_subvolume:
    name: /@home
    device: /dev/vda2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove the @home subvolume if it exists
  community.general.btrfs_subvolume:
    name: /@home
    state: absent
    device: /dev/vda2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a snapshot of the root subvolume named @
  community.general.btrfs_subvolume:
    name: /@
    snapshot_source: /
    device: /dev/vda2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a snapshot of the root subvolume and make it the new default subvolume
  community.general.btrfs_subvolume:
    name: /@
    snapshot_source: /
    default: Yes
    device: /dev/vda2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
    device: /dev/vda2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove the /@ subvolume and recursively delete child subvolumes as required
  community.general.btrfs_subvolume:
    name: /@snapshots/@2022_06_09
    snapshot_source: /@
    recursive: True
    device: /dev/vda2

Inputs

    
name:
    description:
    - Name of the subvolume/snapshot to be targeted.
    required: true
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Indicates the current state of the targeted subvolume.
    type: str

default:
    default: false
    description:
    - Make the subvolume specified by O(name) the filesystem's default subvolume.
    type: bool

automount:
    default: false
    description:
    - Allow the module to temporarily mount the targeted btrfs filesystem in order to
      validate the current state and make any required changes.
    type: bool

recursive:
    default: false
    description:
    - When true, indicates that parent/child subvolumes should be created/removedas necessary
      to complete the operation (for O(state=present) and O(state=absent) respectively).
    type: bool

filesystem_uuid:
    description:
    - A unique identifier assigned to the btrfs filesystem to be targeted.
    - Useful when multiple btrfs filesystems are present to specify which filesystem should
      be targeted.
    type: str

snapshot_source:
    description:
    - Identifies the source subvolume for the created snapshot.
    - Infers that the created subvolume is a snapshot.
    type: str

filesystem_label:
    description:
    - A descriptive label assigned to the btrfs filesystem to be targeted.
    - Useful when multiple btrfs filesystems are present to specify which filesystem should
      be targeted.
    type: str

filesystem_device:
    description:
    - A block device contained within the btrfs filesystem to be targeted.
    - Useful when multiple btrfs filesystems are present to specify which filesystem should
      be targeted.
    type: path

snapshot_conflict:
    choices:
    - skip
    - clobber
    - error
    default: skip
    description:
    - Policy defining behavior when a subvolume already exists at the path of the requested
      snapshot.
    - V(skip) - Create a snapshot only if a subvolume does not yet exist at the target
      location, otherwise indicate that no change is required. Warning, this option does
      not yet verify that the target subvolume was generated from a snapshot of the requested
      source.
    - V(clobber) - If a subvolume already exists at the requested location, delete it
      first. This option is not idempotent and will result in a new snapshot being generated
      on every execution.
    - V(error) - If a subvolume already exists at the requested location, return an error.
      This option is not idempotent and will result in an error on replay of the module.
    type: str

Outputs

filesystem:
  contains:
    default_subvolume:
      description: The ID of the filesystem's default subvolume.
      returned: success and if filesystem is mounted
      sample: 5
      type: int
    devices:
      description: A list of devices assigned to the filesystem.
      returned: success
      sample:
      - /dev/sda1
      - /dev/sdb1
      type: list
    label:
      description: An optional label assigned to the filesystem.
      returned: success
      sample: Tank
      type: str
    subvolumes:
      contains:
        id:
          description: An identifier assigned to the subvolume, unique within the
            containing filesystem.
          sample: 256
          type: int
        mountpoints:
          description: Paths where the subvolume is mounted on the targeted host.
          sample:
          - /home
          type: list
        parent:
          description: The identifier of this subvolume's parent.
          sample: 5
          type: int
        path:
          description: The full path of the subvolume relative to the btrfs fileystem's
            root.
          sample: /@home
          type: str
      description: A list of dicts containing metadata for all of the filesystem's
        subvolumes.
      elements: dict
      returned: success and if filesystem is mounted
      type: list
    uuid:
      description: A unique identifier assigned to the filesystem.
      returned: success
      sample: 96c9c605-1454-49b8-a63a-15e2584c208e
      type: str
  description:
  - A summary of the final state of the targeted btrfs filesystem.
  returned: success
  type: dict
modifications:
  description:
  - A list where each element describes a change made to the target btrfs filesystem.
  elements: str
  returned: Success
  type: list
target_subvolume_id:
  description:
  - The ID of the subvolume specified with the O(name) parameter, either pre-existing
    or created as part of module execution.
  returned: Success and subvolume exists after module execution
  sample: 257
  type: int