Skip to content

Instantly share code, notes, and snippets.

@charignon
Created July 22, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charignon/72871fe890f4482ccd5bb9d6fd9afcdf to your computer and use it in GitHub Desktop.
Save charignon/72871fe890f4482ccd5bb9d6fd9afcdf to your computer and use it in GitHub Desktop.
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
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