Skip to content

Commit 34bff0d

Browse files
authored
Add storage volume mount role (#160)
Signed-off-by: Jim Enright <[email protected]>
1 parent fcfb5df commit 34bff0d

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

roles/mount/defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
mount_volumes: []
4+
# mount_volumes:
5+
# - device:
6+
# mount:
7+
mount_provider: openstack # aws, openstack

roles/mount/meta/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2023 Cloudera, Inc. All Rights Reserved.
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+
# http://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+
galaxy_info:
16+
author: Webster Mudge ([email protected])
17+
description: >
18+
Create and mount an LVM partition for a specified storage volume.
19+
Includes installation of the LVM2 OS package.
20+
company: Cloudera
21+
license: Apache-2.0
22+
23+
min_ansible_version: 2.10
24+
25+
platforms:
26+
- name: Debian
27+
versions: all
28+
- name: Fedora
29+
versions: all
30+
- name: GenericLinux
31+
versions: all
32+
- name: MacOSX
33+
versions: all
34+
- name: Ubuntu
35+
versions: all
36+
37+
galaxy_tags:
38+
- storage
39+
- mount
40+
- cdp
41+
- aws
42+
- openstack

roles/mount/tasks/main.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
3+
- name: Generate map of EBS volume attachments
4+
when: mount_provider == 'aws'
5+
block:
6+
- name: Collect details on mapped EBS volumes
7+
ansible.builtin.setup:
8+
gather_subset:
9+
- hardware
10+
11+
- name: Map NVME volume attachments
12+
when: device.key is match("nvme")
13+
ansible.builtin.set_fact:
14+
ebs_device_map: "{{ ebs_device_map | default({}) | combine({ volume : '/dev/' + device.key }) }}"
15+
loop: "{{ ansible_devices | dict2items }}"
16+
loop_control:
17+
loop_var: device
18+
label: "{{ device.key }}"
19+
vars:
20+
ebs_prefix: nvme-Amazon_Elastic_Block_Store_vol
21+
volume: "vol-{{ device.value.links.ids | select('match', ebs_prefix) | map('regex_replace', '^' + ebs_prefix) | list | first }}"
22+
23+
- name: Set required facts for volumes
24+
ansible.builtin.set_fact:
25+
__storage_volumes_facts: "{{ __storage_volumes_facts | default([]) | union([storage_volume_detail]) }}"
26+
vars:
27+
__device: "{{ ebs_device_map[volume.vol_id] | default(volume.device) }}"
28+
__speared_device: "{{ __device | replace('/', '-') }}"
29+
storage_volume_detail:
30+
device: "{{ __device }}"
31+
partition: "{{ __device + (mount_provider == 'aws') | ternary('p1', '1') }}"
32+
vg_name: "{{ 'vg' + __speared_device }}"
33+
lv_name: "{{ 'lv' + __speared_device }}"
34+
mount: "{{ volume.mount }}"
35+
loop: "{{ storage_volumes }}"
36+
loop_control:
37+
loop_var: volume
38+
label: "{{ __device }}"
39+
40+
- name: Install lvm2 dependency
41+
ansible.builtin.package:
42+
name: lvm2
43+
state: present
44+
45+
- name: Create a new primary partition for LVM
46+
community.general.parted:
47+
device: "{{ volume.device }}"
48+
number: 1
49+
flags: [ lvm ]
50+
state: present
51+
part_start: "0%"
52+
part_end: "100%"
53+
loop: "{{ __storage_volumes_facts }}"
54+
loop_control:
55+
loop_var: volume
56+
label: "{{ volume.device }}"
57+
58+
- name: Create and mount the volume
59+
ansible.builtin.include_tasks: volume.yml
60+
when: volume.mount not in (ansible_mounts | default([]) | map(attribute='mount') | list)
61+
loop: "{{ __storage_volumes_facts }}"
62+
loop_control:
63+
loop_var: volume
64+
label: "{{ volume.device }}"

roles/mount/tasks/volume.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# 'volume' is an entry from '__storage_volume_facts'
3+
4+
- name: Create LVM volume group
5+
community.general.lvg:
6+
vg: "{{ volume.vg_name }}"
7+
pvs: "{{ volume.partition }}"
8+
9+
- name: Create logical volume
10+
community.general.lvol:
11+
vg: "{{ volume.vg_name }}"
12+
lv: "{{ volume.lv_name }}"
13+
size: +100%FREE
14+
force: yes
15+
16+
- name: Format partition as XFS
17+
community.general.filesystem:
18+
dev: "{{ '/'.join(['/dev',volume.vg_name, volume.lv_name]) }}"
19+
fstype: xfs
20+
21+
- name: Create the mount directory
22+
ansible.builtin.file:
23+
path: "{{ volume.mount }}"
24+
state: directory
25+
mode: '0755'
26+
27+
- name: Mount the logical volume
28+
mount:
29+
path: "{{ volume.mount }}"
30+
src: "{{ '/'.join(['/dev',volume.vg_name, volume.lv_name]) }}"
31+
fstype: xfs
32+
state: mounted
33+

0 commit comments

Comments
 (0)