Skip to content

Commit cbecb05

Browse files
committed
Update mount role for ansible-lint, argument specs, and README
Signed-off-by: Webster Mudge <[email protected]>
1 parent 095479c commit cbecb05

File tree

6 files changed

+216
-65
lines changed

6 files changed

+216
-65
lines changed

roles/mount/README.md

Lines changed: 102 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,106 @@
1-
<!--
2-
Copyright 2024 Cloudera, Inc.
1+
# mount
32

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.
74

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.
96

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`).
1617

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+
```

roles/mount/defaults/main.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
---
1+
# Copyright 2025 Cloudera, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
214

3-
mount_volumes: []
415
# mount_volumes:
516
# - device:
617
# mount:
7-
mount_provider: openstack # aws, openstack
18+
mount_fstype: xfs
19+
# mount_provider:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2025 Cloudera, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
---
15+
argument_specs:
16+
main:
17+
short_description: Create and mount a storage volume
18+
description: |
19+
Create, format, and mount an LVM partition for a specified storage volume.
20+
Includes the installation of the LVM2 OS package.
21+
author: Cloudera Labs
22+
options:
23+
mount_volumes:
24+
description:
25+
- Version of the AMD ROCm package.
26+
type: list
27+
elements: dict
28+
required: true
29+
options:
30+
device:
31+
description:
32+
- The device identifier.
33+
type: str
34+
required: true
35+
mount:
36+
description:
37+
- The mount path on the host.
38+
type: path
39+
required: true
40+
fstype:
41+
description:
42+
- Format type for the partition.
43+
- The default format type is defined by O(mount_fstype).
44+
type: str
45+
required: false
46+
mount_fstype:
47+
description:
48+
- Format type for the partition(s).
49+
type: str
50+
required: false
51+
default: xfs
52+
mount_provider:
53+
description:
54+
- The infrastructure provider.
55+
- For V(aws), EBS NVME volume attachments will be mapped and mounted.
56+
type: str
57+
required: false
58+
choices:
59+
- aws
60+
...

roles/mount/meta/main.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

roles/mount/tasks/main.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
# Copyright 2025 Cloudera, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
---
16+
217
- name: Generate map of EBS volume attachments
3-
when: mount_provider == 'aws'
18+
when: mount_provider is defined and mount_provider == 'aws'
419
block:
520
- name: Collect details on mapped EBS volumes
621
ansible.builtin.setup:
@@ -29,11 +44,11 @@
2944
__speared_device: "{{ __device | replace('/', '-') }}"
3045
storage_volume_detail:
3146
device: "{{ __device }}"
32-
partition: "{{ __device + (mount_provider == 'aws') | ternary('p1', '1') }}"
47+
partition: "{{ __device + (mount_provider | default('') == 'aws') | ternary('p1', '1') }}"
3348
vg_name: "{{ 'vg' + __speared_device }}"
3449
lv_name: "{{ 'lv' + __speared_device }}"
3550
mount: "{{ volume.mount }}"
36-
loop: "{{ storage_volumes }}"
51+
loop: "{{ mount_volumes }}"
3752
loop_control:
3853
loop_var: volume
3954
label: "{{ __device }}"
@@ -63,3 +78,5 @@
6378
loop_control:
6479
loop_var: volume
6580
label: "{{ volume.device }}"
81+
82+
...

roles/mount/tasks/volume.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2025 Cloudera, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
---
216
# 'volume' is an entry from '__storage_volume_facts'
317

@@ -13,10 +27,10 @@
1327
size: +100%FREE
1428
force: true
1529

16-
- name: Format partition as XFS
30+
- name: Format partition
1731
community.general.filesystem:
1832
dev: "{{ '/'.join(['/dev', volume.vg_name, volume.lv_name]) }}"
19-
fstype: xfs
33+
fstype: "{{ volume.fstype | default(mount_fstype) }}"
2034

2135
- name: Create the mount directory
2236
ansible.builtin.file:
@@ -28,5 +42,7 @@
2842
ansible.posix.mount:
2943
path: "{{ volume.mount }}"
3044
src: "{{ '/'.join(['/dev', volume.vg_name, volume.lv_name]) }}"
31-
fstype: xfs
45+
fstype: "{{ volume.fstype | default(mount_fstype) }}"
3246
state: mounted
47+
48+
...

0 commit comments

Comments
 (0)