diff --git a/roles/mount/defaults/main.yml b/roles/mount/defaults/main.yml new file mode 100644 index 00000000..544e7208 --- /dev/null +++ b/roles/mount/defaults/main.yml @@ -0,0 +1,7 @@ +--- + +mount_volumes: [] +# mount_volumes: +# - device: +# mount: +mount_provider: openstack # aws, openstack \ No newline at end of file diff --git a/roles/mount/meta/main.yml b/roles/mount/meta/main.yml new file mode 100755 index 00000000..a760df41 --- /dev/null +++ b/roles/mount/meta/main.yml @@ -0,0 +1,42 @@ +# 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 new file mode 100644 index 00000000..af52d43e --- /dev/null +++ b/roles/mount/tasks/main.yml @@ -0,0 +1,64 @@ +--- + +- name: Generate map of EBS volume attachments + when: mount_provider == 'aws' + block: + - name: Collect details on mapped EBS volumes + ansible.builtin.setup: + gather_subset: + - hardware + + - name: Map NVME volume attachments + when: device.key is match("nvme") + ansible.builtin.set_fact: + ebs_device_map: "{{ ebs_device_map | default({}) | combine({ volume : '/dev/' + device.key }) }}" + loop: "{{ ansible_devices | dict2items }}" + loop_control: + loop_var: device + label: "{{ device.key }}" + vars: + ebs_prefix: nvme-Amazon_Elastic_Block_Store_vol + volume: "vol-{{ device.value.links.ids | select('match', ebs_prefix) | map('regex_replace', '^' + ebs_prefix) | list | first }}" + +- name: Set required facts for volumes + ansible.builtin.set_fact: + __storage_volumes_facts: "{{ __storage_volumes_facts | default([]) | union([storage_volume_detail]) }}" + vars: + __device: "{{ ebs_device_map[volume.vol_id] | default(volume.device) }}" + __speared_device: "{{ __device | replace('/', '-') }}" + storage_volume_detail: + device: "{{ __device }}" + partition: "{{ __device + (mount_provider == 'aws') | ternary('p1', '1') }}" + vg_name: "{{ 'vg' + __speared_device }}" + lv_name: "{{ 'lv' + __speared_device }}" + mount: "{{ volume.mount }}" + loop: "{{ storage_volumes }}" + loop_control: + loop_var: volume + label: "{{ __device }}" + +- name: Install lvm2 dependency + ansible.builtin.package: + name: lvm2 + state: present + +- name: Create a new primary partition for LVM + community.general.parted: + device: "{{ volume.device }}" + number: 1 + flags: [ lvm ] + state: present + part_start: "0%" + part_end: "100%" + loop: "{{ __storage_volumes_facts }}" + loop_control: + loop_var: volume + label: "{{ volume.device }}" + +- name: Create and mount the volume + ansible.builtin.include_tasks: volume.yml + when: volume.mount not in (ansible_mounts | default([]) | map(attribute='mount') | list) + loop: "{{ __storage_volumes_facts }}" + loop_control: + loop_var: volume + label: "{{ volume.device }}" \ No newline at end of file diff --git a/roles/mount/tasks/volume.yml b/roles/mount/tasks/volume.yml new file mode 100644 index 00000000..15928f31 --- /dev/null +++ b/roles/mount/tasks/volume.yml @@ -0,0 +1,33 @@ +--- +# 'volume' is an entry from '__storage_volume_facts' + +- name: Create LVM volume group + community.general.lvg: + vg: "{{ volume.vg_name }}" + pvs: "{{ volume.partition }}" + +- name: Create logical volume + community.general.lvol: + vg: "{{ volume.vg_name }}" + lv: "{{ volume.lv_name }}" + size: +100%FREE + force: yes + +- name: Format partition as XFS + community.general.filesystem: + dev: "{{ '/'.join(['/dev',volume.vg_name, volume.lv_name]) }}" + fstype: xfs + +- name: Create the mount directory + ansible.builtin.file: + path: "{{ volume.mount }}" + state: directory + mode: '0755' + +- name: Mount the logical volume + mount: + path: "{{ volume.mount }}" + src: "{{ '/'.join(['/dev',volume.vg_name, volume.lv_name]) }}" + fstype: xfs + state: mounted + \ No newline at end of file