Skip to content

Instantly share code, notes, and snippets.

@jamesdmorgan
Created June 24, 2015 12:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdmorgan/7dd98c35790350629270 to your computer and use it in GitHub Desktop.
Save jamesdmorgan/7dd98c35790350629270 to your computer and use it in GitHub Desktop.
Anisble detect, format and mount filesystem
- 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