Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2017 21:32
What would you like to do?
ansible runbook to set up digital ocean block storage
- 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
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