]> arthur.barton.de Git - AnsibleRoles.git/commitdiff
New "linux-bfs" role
authorAlexander Barton <alex@barton.de>
Tue, 13 Oct 2015 08:42:35 +0000 (10:42 +0200)
committerAlexander Barton <alex@barton.de>
Tue, 13 Oct 2015 08:42:35 +0000 (10:42 +0200)
- Setup "ZFS on Linux" APT repository
- Install packages
- Install "scrub" script
- Install CRON job for scrub script

roles/linux-zfs/defaults/main.yml [new file with mode: 0644]
roles/linux-zfs/files/zfsonlinux.gpg [new file with mode: 0644]
roles/linux-zfs/meta/main.yml [new file with mode: 0644]
roles/linux-zfs/tasks/main.yml [new file with mode: 0644]
roles/linux-zfs/templates/cron.d_zpool-scrub.j2 [new file with mode: 0644]
roles/linux-zfs/templates/zfsonlinux.list.j2 [new file with mode: 0644]
roles/linux-zfs/templates/zpool-scrub.sh.j2 [new file with mode: 0644]

diff --git a/roles/linux-zfs/defaults/main.yml b/roles/linux-zfs/defaults/main.yml
new file mode 100644 (file)
index 0000000..81a5e3e
--- /dev/null
@@ -0,0 +1,5 @@
+---
+# defaults file for linux-zfs
+
+admin_email: "root"
+zfsonlinux_apt_repository: "[arch=amd64] http://archive.zfsonlinux.org/debian"
diff --git a/roles/linux-zfs/files/zfsonlinux.gpg b/roles/linux-zfs/files/zfsonlinux.gpg
new file mode 100644 (file)
index 0000000..4729ed9
Binary files /dev/null and b/roles/linux-zfs/files/zfsonlinux.gpg differ
diff --git a/roles/linux-zfs/meta/main.yml b/roles/linux-zfs/meta/main.yml
new file mode 100644 (file)
index 0000000..e6f096c
--- /dev/null
@@ -0,0 +1,5 @@
+---
+# meta file for linux-zfs
+
+dependencies:
+  - { role: debian-base }
diff --git a/roles/linux-zfs/tasks/main.yml b/roles/linux-zfs/tasks/main.yml
new file mode 100644 (file)
index 0000000..0574b7f
--- /dev/null
@@ -0,0 +1,62 @@
+---
+# tasks file for linux-zfs
+
+- name: install "ZFS on Linux" repository GnuPG key
+  tags:
+    - zfs
+    - packages
+  copy: >
+    dest=/etc/apt/trusted.gpg.d/
+    group=root
+    mode=644
+    owner=root
+    src=zfsonlinux.gpg
+  notify:
+    - update APT repositories
+
+- name: install "ZFS on Linux" repository configuration
+  tags:
+    - zfs
+    - packages
+  template: >
+    dest=/etc/apt/sources.list.d/zfsonlinux.list
+    group=root
+    mode=644
+    owner=root
+    src=zfsonlinux.list.j2
+  notify:
+    - update APT repositories
+
+- meta: flush_handlers
+  tags:
+    - zfs
+    - packages
+
+- name: install "ZFS on Linux" packages
+  tags:
+    - packages
+    - zfs
+  apt: >
+    state=installed
+    name=debian-zfs
+
+- name: setup /usr/local/sbin/zpool-scrub.sh file
+  tags:
+    - zfs
+  template: >
+    dest=/usr/local/sbin/zpool-scrub.sh
+    group=root
+    mode=644
+    owner=root
+    src=zpool-scrub.sh.j2
+
+- name: setup /etc/cton.d/zpool-scrub file
+  tags:
+    - cron
+    - zfs
+  template: >
+    dest=/etc/cron.d/zpool-scrub
+    group=root
+    mode=644
+    owner=root
+    src=cron.d_zpool-scrub.j2
diff --git a/roles/linux-zfs/templates/cron.d_zpool-scrub.j2 b/roles/linux-zfs/templates/cron.d_zpool-scrub.j2
new file mode 100644 (file)
index 0000000..40381f5
--- /dev/null
@@ -0,0 +1,11 @@
+# /etc/cron.d/zpool-scrub
+# ---
+#  {{ ansible_managed }}
+# ---
+
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin/:/bin
+MAILTO={{ admin_email }}
+
+# m h  dom mon dow  user  command
+
+42 12  * * 2  root  /usr/local/sbin/zpool-scrub.sh
diff --git a/roles/linux-zfs/templates/zfsonlinux.list.j2 b/roles/linux-zfs/templates/zfsonlinux.list.j2
new file mode 100644 (file)
index 0000000..9b9d26e
--- /dev/null
@@ -0,0 +1,6 @@
+# /etc/apt/sources.list.d/zfsonlinux.list -- "ZFS on Linux" repository config
+# ---
+#  {{ ansible_managed }}
+# ---
+
+deb {{zfsonlinux_apt_repository}} {{ansible_distribution_release}} main
diff --git a/roles/linux-zfs/templates/zpool-scrub.sh.j2 b/roles/linux-zfs/templates/zpool-scrub.sh.j2
new file mode 100644 (file)
index 0000000..a0b6cad
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+# /usr/local/sbin/backup-script-wrapper
+# ---
+#  {{ ansible_managed }}
+# ---
+
+NAME=$(basename "$0")
+
+pools=$(zpool list -H | cut -f1)
+if [ $? -ne 0 ]; then
+       echo "$NAME: Failed to list ZFS pools, aborting!"
+       exit 1
+fi
+if [ -z "$pools" ]; then
+       # No pools found, nothing to do, ok.
+       exit 0
+fi
+
+wait_for_scrub_done() {
+       while true; do
+               zpool status "$1" 2>/dev/null | fgrep 'scrub in progress' >/dev/null
+               [ $? -eq 0 ] || return 0
+               sleep 60
+       done
+}
+
+for pool in $pools; do
+       echo "Scrubbing ZFS storage pool \"$pool\" ..."
+       echo -n "Started: "; date
+       zpool scrub "$pool"
+       if [ $? -eq 0 ]; then
+               wait_for_scrub_done "$pool"
+               echo -n "Done: "; date
+       else
+               echo "Failed to start scrubbing!?"
+               zpool scrub -s "$pool" >/dev/null 2>&1
+               sleep 5
+       fi
+       echo
+done
+
+# Show status of ZFS storage pools
+zpool status