Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 102 additions & 13 deletions roles/mount/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,106 @@
<!--
Copyright 2024 Cloudera, Inc.
# mount

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Create, format, and mount a storage volume.

https://www.apache.org/licenses/LICENSE-2.0
This role automates the process of creating, formatting, and mounting a logical volume management (LVM) partition on a specified device. It handles the installation of the `LVM2` operating system package if it's not already present.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
The role will:
- Install the `lvm2` package.
- Identify the specified block device(s).
- Create a Physical Volume (PV) on the device.
- Create a Volume Group (VG) on the PV.
- Create a Logical Volume (LV) within the VG.
- Format the Logical Volume with the specified or default filesystem type (`xfs` by default).
- Mount the Logical Volume to the specified mount path.
- Configure `fstab` for persistent mounting across reboots.
- Optionally, for `aws` provider, it will handle NVMe device name mapping (e.g., `/dev/nvme0n1` to `/dev/xvda`).

# mount
## Requirements

- Target host must have unpartitioned, unformatted block devices available.
- For `aws` provider, instances must have EBS volumes attached.

## Dependencies

None.

## Role Variables

| Parameter | Type | Default Value | Required | Description |
|---------------------|------------------|---------------|----------|------------------------------------------------------------------------------------------------------------------------------------------|
| `mount_volumes` | `list` of `dict` | - | `true` | A list of dictionaries, where each dictionary defines a storage volume to be created, formatted, and mounted. |
| `device` | `str` | - | `true` | The identifier of the block device (e.g., `/dev/sdb`, `/dev/nvme1n1`). |
| `mount` | `path` | - | `true` | The absolute path on the host where the volume should be mounted (e.g., `/mnt/data`, `/opt/app`). |
| `fstype` | `str` | `mount_fstype`| `false` | The filesystem type to format the partition with (e.g., `xfs`, `ext4`). If not specified, the value of `mount_fstype` will be used. |
| `mount_fstype` | `str` | `xfs` | `false` | The default filesystem type to format partitions with if not specified per volume in `mount_volumes`. |
| `mount_provider` | `str` | - | `false` | The infrastructure provider where the volume is being provisioned. If set to `aws`, EBS NVMe volume attachments will be mapped correctly. *Choices*: `aws` |

## Examples

Basic usage to create and mount a single volume using the default `xfs` filesystem:

```yaml
- name: Create and mount a data volume with default filesystem
ansible.builtin.import_role:
name: cloudera.exe.mount
vars:
mount_volumes:
- device: "/dev/sdb"
mount: "/mnt/data"
# mount_fstype will default to 'xfs'

- name: Provision multiple storage volumes with a custom default filesystem
ansible.builtin.import_role:
name: cloudera.exe.mount
vars:
mount_fstype: "ext4" # All volumes will be formatted with ext4 unless overridden
mount_volumes:
- device: "/dev/sdb"
mount: "/mnt/data1"
- device: "/dev/sdc"
mount: "/var/lib/app_data"

- name: Provision volumes with mixed filesystem types
ansible.builtin.import_role:
name: cloudera.exe.mount
vars:
mount_fstype: "xfs" # Global default, but can be overridden
mount_volumes:
- device: "/dev/sdb"
mount: "/mnt/data_xfs"
fstype: "xfs" # Explicitly xfs, matches default
- device: "/dev/sdc"
mount: "/mnt/data_ext4"
fstype: "ext4" # Explicitly ext4, overrides global default

- name: Create and mount volumes on an AWS instance with specific filesystems
ansible.builtin.import_role:
name: cloudera.exe.mount
vars:
mount_provider: "aws"
mount_volumes:
- device: "/dev/nvme0n1" # Role will map this to the correct /dev/xvd*
mount: "/mnt/ebs_volume_1"
fstype: "xfs"
- device: "/dev/nvme1n1"
mount: "/var/log/application"
fstype: "ext4"
```

## License

```
Copyright 2025 Cloudera, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
18 changes: 15 additions & 3 deletions roles/mount/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
---
# Copyright 2025 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

mount_volumes: []
# mount_volumes:
# - device:
# mount:
mount_provider: openstack # aws, openstack
mount_fstype: xfs
# mount_provider:
60 changes: 60 additions & 0 deletions roles/mount/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2025 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
argument_specs:
main:
short_description: Create and mount a storage volume
description: |
Create, format, and mount an LVM partition for a specified storage volume.
Includes the installation of the LVM2 OS package.
author: Cloudera Labs
options:
mount_volumes:
description:
- Version of the AMD ROCm package.
type: list
elements: dict
required: true
options:
device:
description:
- The device identifier.
type: str
required: true
mount:
description:
- The mount path on the host.
type: path
required: true
fstype:
description:
- Format type for the partition.
- The default format type is defined by O(mount_fstype).
type: str
required: false
mount_fstype:
description:
- Format type for the partition(s).
type: str
required: false
default: xfs
mount_provider:
description:
- The infrastructure provider.
- For V(aws), EBS NVME volume attachments will be mapped and mounted.
type: str
required: false
choices:
- aws
...
43 changes: 0 additions & 43 deletions roles/mount/meta/main.yml

This file was deleted.

23 changes: 20 additions & 3 deletions roles/mount/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Copyright 2025 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---

- name: Generate map of EBS volume attachments
when: mount_provider == 'aws'
when: mount_provider is defined and mount_provider == 'aws'
block:
- name: Collect details on mapped EBS volumes
ansible.builtin.setup:
Expand Down Expand Up @@ -29,11 +44,11 @@
__speared_device: "{{ __device | replace('/', '-') }}"
storage_volume_detail:
device: "{{ __device }}"
partition: "{{ __device + (mount_provider == 'aws') | ternary('p1', '1') }}"
partition: "{{ __device + (mount_provider | default('') == 'aws') | ternary('p1', '1') }}"
vg_name: "{{ 'vg' + __speared_device }}"
lv_name: "{{ 'lv' + __speared_device }}"
mount: "{{ volume.mount }}"
loop: "{{ storage_volumes }}"
loop: "{{ mount_volumes }}"
loop_control:
loop_var: volume
label: "{{ __device }}"
Expand Down Expand Up @@ -63,3 +78,5 @@
loop_control:
loop_var: volume
label: "{{ volume.device }}"

...
22 changes: 19 additions & 3 deletions roles/mount/tasks/volume.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2025 Cloudera, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
# 'volume' is an entry from '__storage_volume_facts'

Expand All @@ -13,10 +27,10 @@
size: +100%FREE
force: true

- name: Format partition as XFS
- name: Format partition
community.general.filesystem:
dev: "{{ '/'.join(['/dev', volume.vg_name, volume.lv_name]) }}"
fstype: xfs
fstype: "{{ volume.fstype | default(mount_fstype) }}"

- name: Create the mount directory
ansible.builtin.file:
Expand All @@ -28,5 +42,7 @@
ansible.posix.mount:
path: "{{ volume.mount }}"
src: "{{ '/'.join(['/dev', volume.vg_name, volume.lv_name]) }}"
fstype: xfs
fstype: "{{ volume.fstype | default(mount_fstype) }}"
state: mounted

...
Loading