Skip to content

Instantly share code, notes, and snippets.

@clarkem
Created December 16, 2016 19:26
Show Gist options
  • Save clarkem/4bf0790cdf1356bc33cc7755cd35022d to your computer and use it in GitHub Desktop.
Save clarkem/4bf0790cdf1356bc33cc7755cd35022d to your computer and use it in GitHub Desktop.
- name: Check if device /dev/xvd_ present
shell: fdisk -l | grep 'Disk {{device}}' | wc -l
changed_when: False
register: device_present
- name: Check if partition /dev/xvd_1 present
shell: fdisk -l | grep {{device}}1 | wc -l
changed_when: False
register: partition_present
when: device_present.stdout is defined and device_present.stdout|int == 0
# it's present but has no partition
- name: Create a partition table,
shell: "echo -e 'n\np\n1\n\n\nw\n' | fdisk {{device}} && mkfs -t {{fs_type}} {{device}}1 && tune2fs -m 0 {{device}}1"
when: device_present.stdout is defined and not device_present.stdout|int == 0
# if it's present & has partition & has fs
- name: mount the device
mount:
name: {{ mount_point }}
src: /dev/{{ device }}1
fstype: {{ fs_type }}
opts: noatime
state: present
when: fs_present.stdout is defined and fs_present.stdout|int == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment