Created
December 16, 2016 19:26
-
-
Save clarkem/4bf0790cdf1356bc33cc7755cd35022d to your computer and use it in GitHub Desktop.
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: 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