-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# 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. | ||
|
||
--- | ||
|
||
- name: Configure local SSDs | ||
become: true | ||
hosts: localhost | ||
vars: | ||
raid_name: localssd | ||
array_dev: /dev/md/{{ raid_name }} | ||
fstype: ext4 | ||
interface: nvme | ||
mode: '0755' | ||
tasks: | ||
- name: Get local SSD devices | ||
ansible.builtin.find: | ||
file_type: link | ||
path: /dev/disk/by-id | ||
patterns: google-local-{{ "nvme-" if interface == "nvme" else "" }}ssd-* | ||
register: local_ssd_devices | ||
|
||
- name: Exit if zero local ssd found | ||
ansible.builtin.meta: end_play | ||
when: local_ssd_devices.files | length == 0 | ||
|
||
- name: Install mdadm | ||
ansible.builtin.package: | ||
name: mdadm | ||
state: present | ||
|
||
- name: Force RAID array if only 1 local SSD | ||
ansible.builtin.shell: mdadm --create {{ array_dev }} --name={{ raid_name }} --homehost=any --level=0 --raid-devices=1 /dev/disk/by-id/google-local-nvme-ssd-0 --force | ||
args: | ||
creates: "{{ array_dev }}" | ||
when: local_ssd_devices.files | length == 1 | ||
|
||
- name: Create RAID array | ||
ansible.builtin.shell: mdadm --create {{ array_dev }} --name={{ raid_name }} --homehost=any --level=0 --raid-devices={{ local_ssd_devices.files | length }} /dev/disk/by-id/google-local-nvme-ssd-* | ||
args: | ||
creates: "{{ array_dev }}" | ||
when: local_ssd_devices.files | length >= 2 | ||
|
||
- name: Format filesystem | ||
community.general.filesystem: | ||
fstype: "{{ fstype }}" | ||
device: "{{ array_dev }}" | ||
opts: '{{ "-m 0" if fstype == "ext4" else "" }}' | ||
|
||
- name: Mount RAID array | ||
ansible.posix.mount: | ||
src: "{{ array_dev }}" | ||
path: '{{ mountpoint | default("/mnt/" + raid_name) }}' | ||
fstype: "{{ fstype }}" | ||
# the nofail option is critical as it enables the boot process to complete on machines | ||
# that were powered off and had local SSD contents discarded; without this option | ||
# VMs may fail to join the network | ||
opts: discard,defaults,nofail | ||
state: mounted | ||
|
||
- name: Set mount permissions | ||
ansible.builtin.file: | ||
path: '{{ mountpoint | default("/mnt/" + raid_name) }}' | ||
state: directory | ||
mode: "{{ mode }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters