Created
June 24, 2015 12:06
-
-
Save jamesdmorgan/7dd98c35790350629270 to your computer and use it in GitHub Desktop.
Anisble detect, format and mount filesystem
This file contains hidden or 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
- hosts: all | |
vars: | |
mount_point: | |
fstype: ext4 | |
dev: /dev/xvdf | |
mount: /opt | |
opts: "rw" | |
state: mounted | |
tasks: | |
- name: get system details | |
stat: path={{ mount_point.dev }} | |
register: check_mount | |
- debug: | |
msg: > | |
{{ check_mount.stat }} | |
# Check the type of filesysttem if its data we need to format | |
- shell: file -s {{ mount_point.dev }} | |
register: fs | |
- set_fact: | |
format_fs: true | |
when: "'{{ mount_point.dev }}: data' in fs.stdout " | |
- name: Format filesystem | |
filesystem: fstype={{ mount_point.fstype }} dev={{ mount_point.dev }} | |
when: format_fs is defined and format_fs == true | |
# Check the type of filesysttem if its data we need to format | |
- shell: file -s {{ mount_point.dev }} | |
register: fs | |
- debug: | |
msg: > | |
{{ fs }} | |
- name: Mount filesystem | |
mount: | |
fstype: "{{ mount_point.fstype }}" | |
src: "{{ mount_point.dev }}" | |
name: "{{ mount_point.mount }}" | |
opts: "{{ mount_point.opts }}" | |
state: "{{ mount_point.state }}" | |
register: mount_info | |
- debug: | |
gather_facts: true | |
msg: > | |
{{ mount_info }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment