Skip to content

Commit

Permalink
Merge pull request #14 from bionix/feature/fs_types_and_alignment
Browse files Browse the repository at this point in the history
Add feature/more_fs_types and feature/better_alignment
  • Loading branch information
MiLk committed Mar 29, 2017
2 parents 382adef + bb7ffe4 commit b667400
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ 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
user: www-data
group: www-data
- disk: /dev/sdb
fstype: ext4
mount_options: defaults
mount: /data
user: www-data
group: www-data
disable_periodic_fsck: false
```
* `disk` is the device, you want to mount.
Expand All @@ -30,6 +31,7 @@ disk_additional_disks:
* `mount` is the directory where the new disk should be mounted.
* `user` sets owner of the mount directory (default: `root`).
* `group` sets group of the mount directory (default: `root`).
* `disable_periodic_fsck` deactivates the periodic ext3/4 filesystem check for the new disk.

You can add:
* `disk_package_use` is the required package manager module to use (yum, apt, etc). The default 'auto' will use existing facts or try to autodetect it.
Expand All @@ -38,6 +40,17 @@ 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)
- [xfs](http://en.wikipedia.org/wiki/XFS) *
- [btrfs](http://en.wikipedia.org/wiki/BTRFS) *

*) Note: To use these filesystems you have to define and install additional software packages. Please estimate the right package names for your operating system.

```yaml
# inventory/group_vars/GROUP_NAME
additional_fs_utils:
- xfsprogs # package for mkfs.xfs on RedHat / Ubuntu
- btrfs-progs # package for mkfs.btrfs on CentOS / Debian
```

How it works
------------
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# See README for syntax and usage.
disk_additional_disks: []
disk_package_use: auto
additional_fs_utils: []
32 changes: 31 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@
when: disk_additional_disks
tags: ['disk', 'pkgs']

- name: "Install additional fs progs"
package:
name: "{{ item }}"
state: present
with_items: "{{ additional_fs_utils|default([]) }}"
when: additional_fs_utils is defined
tags: ['disk', 'pkgs']

- name: "Get disk alignment for disks"
shell: |
if
[[ -e /sys/block/{{ item.disk | basename }}/queue/optimal_io_size && -e /sys/block/{{ item.disk | basename }}/alignment_offset && -e /sys/block/{{ item.disk | basename }}/queue/physical_block_size ]];
then
echo $[$(( ($(cat /sys/block/{{ item.disk | basename }}/queue/optimal_io_size) + $(cat /sys/block/{{ item.disk | basename }}/alignment_offset)) / $(cat /sys/block/{{ item.disk | basename }}/queue/physical_block_size) )) | 2048];
else
echo 2048;
fi
args:
creates: '{{ item.disk }}1'
executable: '/bin/bash'
with_items: '{{ disk_additional_disks }}'
register: disk_offset
tags: ['disk']

- name: "Partition additional disks"
shell: |
if
[ -b {{ item.disk }} ]
then
[ -b {{ item.disk }}1 ] || parted --script "{{ item.disk }}" mklabel gpt mkpart primary 1MiB 100%
[ -b {{ item.disk }}1 ] || parted -a optimal --script "{{ item.disk }}" mklabel gpt mkpart primary {{ disk_offset.stdout|default("2048") }}s 100% && sleep 5 && partprobe {{ item.disk }}; sleep 5
fi
args:
creates: '{{ item.disk }}1'
Expand All @@ -28,6 +52,12 @@
with_items: '{{ disk_additional_disks }}'
tags: ['disk']

- name: "Disable periodic fsck on ext3 or ext4 formatted disks"
shell: tune2fs -c0 -i0 {{ item.disk }}1
with_items: '{{ disk_additional_disks }}'
when: "disk_additional_disks and ( item.fstype == 'ext4' or item.fstype == 'ext3' ) and item.disable_periodic_fsck|bool"
tags: ['disk']

- name: "Ensure the mount directory exists"
file:
path: '{{ item.mount }}'
Expand Down

0 comments on commit b667400

Please sign in to comment.