diff --git a/roles/mount/README.md b/roles/mount/README.md index a2cfe457..cfc0fc0d 100644 --- a/roles/mount/README.md +++ b/roles/mount/README.md @@ -1,17 +1,106 @@ - +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. +``` diff --git a/roles/mount/defaults/main.yml b/roles/mount/defaults/main.yml index bbc1878b..9ad40656 100644 --- a/roles/mount/defaults/main.yml +++ b/roles/mount/defaults/main.yml @@ -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: diff --git a/roles/mount/meta/argument_specs.yml b/roles/mount/meta/argument_specs.yml new file mode 100644 index 00000000..26c90595 --- /dev/null +++ b/roles/mount/meta/argument_specs.yml @@ -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 +... diff --git a/roles/mount/meta/main.yml b/roles/mount/meta/main.yml deleted file mode 100755 index dc7e3aa6..00000000 --- a/roles/mount/meta/main.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -# Copyright 2023 Cloudera, Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -galaxy_info: - author: Webster Mudge (wmudge@cloudera.com) - description: > - Create and mount an LVM partition for a specified storage volume. - Includes installation of the LVM2 OS package. - company: Cloudera - license: Apache-2.0 - - min_ansible_version: 2.10 - - platforms: - - name: Debian - versions: all - - name: Fedora - versions: all - - name: GenericLinux - versions: all - - name: MacOSX - versions: all - - name: Ubuntu - versions: all - - galaxy_tags: - - storage - - mount - - cdp - - aws - - openstack diff --git a/roles/mount/tasks/main.yml b/roles/mount/tasks/main.yml index e53de078..5adca01a 100644 --- a/roles/mount/tasks/main.yml +++ b/roles/mount/tasks/main.yml @@ -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: @@ -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 }}" @@ -63,3 +78,5 @@ loop_control: loop_var: volume label: "{{ volume.device }}" + +... diff --git a/roles/mount/tasks/volume.yml b/roles/mount/tasks/volume.yml index bb5d88e3..031f175a 100644 --- a/roles/mount/tasks/volume.yml +++ b/roles/mount/tasks/volume.yml @@ -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' @@ -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: @@ -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 + +...