|
1 | | -<!-- |
2 | | - Copyright 2024 Cloudera, Inc. |
| 1 | +# mount |
3 | 2 |
|
4 | | - Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - you may not use this file except in compliance with the License. |
6 | | - You may obtain a copy of the License at |
| 3 | +Create, format, and mount a storage volume. |
7 | 4 |
|
8 | | - https://www.apache.org/licenses/LICENSE-2.0 |
| 5 | +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. |
9 | 6 |
|
10 | | - Unless required by applicable law or agreed to in writing, software |
11 | | - distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - See the License for the specific language governing permissions and |
14 | | - limitations under the License. |
15 | | ---> |
| 7 | +The role will: |
| 8 | +- Install the `lvm2` package. |
| 9 | +- Identify the specified block device(s). |
| 10 | +- Create a Physical Volume (PV) on the device. |
| 11 | +- Create a Volume Group (VG) on the PV. |
| 12 | +- Create a Logical Volume (LV) within the VG. |
| 13 | +- Format the Logical Volume with the specified or default filesystem type (`xfs` by default). |
| 14 | +- Mount the Logical Volume to the specified mount path. |
| 15 | +- Configure `fstab` for persistent mounting across reboots. |
| 16 | +- Optionally, for `aws` provider, it will handle NVMe device name mapping (e.g., `/dev/nvme0n1` to `/dev/xvda`). |
16 | 17 |
|
17 | | -# mount |
| 18 | +## Requirements |
| 19 | + |
| 20 | +- Target host must have unpartitioned, unformatted block devices available. |
| 21 | +- For `aws` provider, instances must have EBS volumes attached. |
| 22 | + |
| 23 | +## Dependencies |
| 24 | + |
| 25 | +None. |
| 26 | + |
| 27 | +## Role Variables |
| 28 | + |
| 29 | +| Parameter | Type | Default Value | Required | Description | |
| 30 | +|---------------------|------------------|---------------|----------|------------------------------------------------------------------------------------------------------------------------------------------| |
| 31 | +| `mount_volumes` | `list` of `dict` | - | `true` | A list of dictionaries, where each dictionary defines a storage volume to be created, formatted, and mounted. | |
| 32 | +| `device` | `str` | - | `true` | The identifier of the block device (e.g., `/dev/sdb`, `/dev/nvme1n1`). | |
| 33 | +| `mount` | `path` | - | `true` | The absolute path on the host where the volume should be mounted (e.g., `/mnt/data`, `/opt/app`). | |
| 34 | +| `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. | |
| 35 | +| `mount_fstype` | `str` | `xfs` | `false` | The default filesystem type to format partitions with if not specified per volume in `mount_volumes`. | |
| 36 | +| `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` | |
| 37 | + |
| 38 | +## Examples |
| 39 | + |
| 40 | +Basic usage to create and mount a single volume using the default `xfs` filesystem: |
| 41 | + |
| 42 | +```yaml |
| 43 | +- name: Create and mount a data volume with default filesystem |
| 44 | + ansible.builtin.import_role: |
| 45 | + name: cloudera.exe.mount |
| 46 | + vars: |
| 47 | + mount_volumes: |
| 48 | + - device: "/dev/sdb" |
| 49 | + mount: "/mnt/data" |
| 50 | + # mount_fstype will default to 'xfs' |
| 51 | + |
| 52 | +- name: Provision multiple storage volumes with a custom default filesystem |
| 53 | + ansible.builtin.import_role: |
| 54 | + name: cloudera.exe.mount |
| 55 | + vars: |
| 56 | + mount_fstype: "ext4" # All volumes will be formatted with ext4 unless overridden |
| 57 | + mount_volumes: |
| 58 | + - device: "/dev/sdb" |
| 59 | + mount: "/mnt/data1" |
| 60 | + - device: "/dev/sdc" |
| 61 | + mount: "/var/lib/app_data" |
| 62 | + |
| 63 | +- name: Provision volumes with mixed filesystem types |
| 64 | + ansible.builtin.import_role: |
| 65 | + name: cloudera.exe.mount |
| 66 | + vars: |
| 67 | + mount_fstype: "xfs" # Global default, but can be overridden |
| 68 | + mount_volumes: |
| 69 | + - device: "/dev/sdb" |
| 70 | + mount: "/mnt/data_xfs" |
| 71 | + fstype: "xfs" # Explicitly xfs, matches default |
| 72 | + - device: "/dev/sdc" |
| 73 | + mount: "/mnt/data_ext4" |
| 74 | + fstype: "ext4" # Explicitly ext4, overrides global default |
| 75 | + |
| 76 | +- name: Create and mount volumes on an AWS instance with specific filesystems |
| 77 | + ansible.builtin.import_role: |
| 78 | + name: cloudera.exe.mount |
| 79 | + vars: |
| 80 | + mount_provider: "aws" |
| 81 | + mount_volumes: |
| 82 | + - device: "/dev/nvme0n1" # Role will map this to the correct /dev/xvd* |
| 83 | + mount: "/mnt/ebs_volume_1" |
| 84 | + fstype: "xfs" |
| 85 | + - device: "/dev/nvme1n1" |
| 86 | + mount: "/var/log/application" |
| 87 | + fstype: "ext4" |
| 88 | +``` |
| 89 | +
|
| 90 | +## License |
| 91 | +
|
| 92 | +``` |
| 93 | +Copyright 2025 Cloudera, Inc. |
| 94 | + |
| 95 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 96 | +you may not use this file except in compliance with the License. |
| 97 | +You may obtain a copy of the License at |
| 98 | + |
| 99 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 100 | + |
| 101 | +Unless required by applicable law or agreed to in writing, software |
| 102 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 103 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 104 | +See the License for the specific language governing permissions and |
| 105 | +limitations under the License. |
| 106 | +``` |
0 commit comments