From da1455d8b3b51d9980b7078977fa50298629accf Mon Sep 17 00:00:00 2001 From: Emilien Kenler Date: Thu, 14 May 2015 16:54:37 +0900 Subject: [PATCH] Initial commit --- LICENSE | 21 +++++++++++++++++++ README.md | 40 +++++++++++++++++++++++++++++++++++++ meta/main.yml | 19 ++++++++++++++++++ tasks/debian.yml | 14 +++++++++++++ tasks/main.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ tasks/ubuntu.yml | 14 +++++++++++++ vars/main.yml | 4 ++++ 7 files changed, 164 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 meta/main.yml create mode 100644 tasks/debian.yml create mode 100644 tasks/main.yml create mode 100644 tasks/ubuntu.yml create mode 100644 vars/main.yml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d77bf2a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Wizcorp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..628077d --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +Disk +==== + +This role allows you to format extra disks and attach them to different mount points. + +You can use it to move the data of different services to another disk. + +Configuration +------------- + +### Inventory + +Because the configuration for additional disks must be stored using the YAML +syntax, you have to write it in a `group_vars` directory. + +```yaml +# inventory/group_vars/GROUP_NAME +disk_additional_disks: +- disk: /dev/sdb + fstype: ext4 + mount_options: defaults + mount: /data +``` + +* `disk` is the device, you want to mount. +* `fstype` allows you to choose the filesystem to use with the new disk. +* `mount_options` allows you to specify custom mount options. +* `mount` is the directory where the new disk should be mounted. + +The following filesystems are currently supported: +- [ext2](http://en.wikipedia.org/wiki/Ext2) +- [ext3](http://en.wikipedia.org/wiki/Ext3) +- [ext4](http://en.wikipedia.org/wiki/Ext4) + +How it works +------------ + +It uses `sfdisk` to partition the disk with a single primary partition spanning the entire disk. +The specified filesystem will then be created with `mkfs`. +Finally the new partition will be mounted to the specified mount path. diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..39b6f29 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,19 @@ +galaxy_info: + author: Emilien Kenler + description: This role allows setting up extra disks and their mount points + company: Wizcorp K.K. + license: MIT + min_ansible_version: 1.8.1 + platforms: + - name: EL + versions: + - 6 + - 7 + - name: Debian + versions: + - wheezy + - name: Ubuntu + versions: + - all + categories: + - system diff --git a/tasks/debian.yml b/tasks/debian.yml new file mode 100644 index 0000000..8f46a39 --- /dev/null +++ b/tasks/debian.yml @@ -0,0 +1,14 @@ +- name: "apt-get update" + shell: | + apt-get update + tags: + - disk + - pkgs + +- name: "Install util-linux" + apt: > + name=util-linux + state=present + tags: + - disk + - pkgs diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..b24186f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,52 @@ +##################### +# Ubuntu +- include: ubuntu.yml + when: ansible_distribution == 'Ubuntu' and disk_additional_disks + +##################### +# Debian +- include: debian.yml + when: ansible_distribution == 'Debian' and disk_additional_disks + +- name: "Check if the specified filesystem is supported" + fail: > + msg="Unsupported filesystem '{{ item.fstype }}' for disk '{{ item.disk }}'" + when: item.fstype not in disk_supported_fs_types + with_items: disk_additional_disks + tags: + - disk + +- name: "Format additional disks" + shell: | + executable=/bin/bash + if + [ -e {{ item.disk }} ] + then + [ -b {{ item.disk }}1 ] || echo 0,,8e | sfdisk {{ item.disk }} + [[ `blkid | grep {{ item.disk }}1 | grep {{ item.fstype }}` ]] || mkfs.{{ item.fstype }} {{ item.disk }}1 + fi + with_items: disk_additional_disks + tags: + - disk + +- name: "Ensure the /data directory exists" + file: > + path={{ item.mount }} + owner=root + group=root + state=directory + with_items: disk_additional_disks + tags: + - disk + +- name: "Mount additional disk" + mount: > + name={{ item.mount }} + fstype={{ item.fstype }} + opts={{ item.mount_options }} + passno=0 + src={{ item.disk }}1 + state=mounted + with_items: disk_additional_disks + tags: + - disk diff --git a/tasks/ubuntu.yml b/tasks/ubuntu.yml new file mode 100644 index 0000000..8f46a39 --- /dev/null +++ b/tasks/ubuntu.yml @@ -0,0 +1,14 @@ +- name: "apt-get update" + shell: | + apt-get update + tags: + - disk + - pkgs + +- name: "Install util-linux" + apt: > + name=util-linux + state=present + tags: + - disk + - pkgs diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..c12c0c0 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,4 @@ +disk_supported_fs_types: + - ext2 + - ext3 + - ext4