ansible runbook to set up digital ocean block storage
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
- name: Get the volume name | |
shell: ls /dev/disk/by-id/ | grep -v part | |
register: volume_name_raw | |
- set_fact: | |
volume_name: "{{ volume_name_raw.stdout }}" | |
- name: Check if the volume is already setup | |
command: grep '{{ volume_name }}' /etc/fstab -q | |
register: volume_present | |
ignore_errors: True | |
- name: Label the volume | |
command: parted /dev/disk/by-id/{{ volume_name }} mklabel gpt | |
when: volume_present|failed | |
- name: Create an ext4 partition | |
command: parted -a opt /dev/disk/by-id/{{ volume_name }} mkpart primary ext4 0% 100% | |
when: volume_present|failed | |
- name: Build the ext4 metadata | |
command: mkfs.ext4 /dev/disk/by-id/{{ volume_name }}-part1 | |
when: volume_present|failed | |
- name: Create the mount point | |
command: mkdir -p /mnt/data | |
when: volume_present|failed | |
- name: Mount volume read-write | |
mount: | |
path: /mnt/data | |
src: /dev/disk/by-id/{{ volume_name }}-part1 | |
fstype: ext4 | |
opts: defaults,discard | |
state: mounted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment