Last active
August 7, 2021 09:49
-
-
Save timfoster/420f3675c4672e2ca4374fd770fec2a8 to your computer and use it in GitHub Desktop.
Configure ZFS on Linux on a CentOS system.
This file contains 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
# | |
# A series of Ansible tasks to download and configure zfs on linux | |
# If this is a HVM on SmartOS using one of the linux images, | |
# ( e.g.https://images.joyent.com/images?name=centos-7&type=zvol ) | |
# replace the /data ext4 filesystem created by default with a zpool called | |
# tank, and create tank/data, mounting it to /data | |
# | |
--- | |
- name: See if we already have the zfs source repo | |
stat: | |
path: /etc/yum.repos.d/zfs.repo | |
register: stat_result | |
- name: Download zol RPMs for this version of centos | |
get_url: | |
url: http://download.zfsonlinux.org/epel/zfs-release.el{{ ansible_distribution_version | replace('.', '_') }}.noarch.rpm | |
dest: /tmp | |
register: zfs_rpm | |
when: stat_result.stat.exists == False | |
- name: Install zfs source repo package | |
package: | |
name: "{{ zfs_rpm.dest }}" | |
state: present | |
when: stat_result.stat.exists == False | |
- name: Verify the fingerprint | |
command: | |
cmd: gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux | |
register: gpg | |
failed_when: '"C93A FFFD 9F3F 7B03 C310 CEB6 A9D5 A1C0 F14A B620" not in gpg.stdout' | |
- name: Disable dkms zfs repo | |
ini_file: | |
path: /etc/yum.repos.d/zfs.repo | |
section: zfs | |
option: enabled | |
value: "0" | |
- name: Enable zfs-kmod | |
ini_file: | |
path: /etc/yum.repos.d/zfs.repo | |
section: zfs-kmod | |
option: enabled | |
value: "1" | |
- name: Install zfs | |
package: | |
name: zfs | |
state: installed | |
- name: Load the zfs module at boot | |
lineinfile: | |
path: /etc/modules-load.d/zfs.conf | |
line: zfs | |
create: yes | |
- name: Load the zfs module now | |
modprobe: | |
name: zfs | |
state: present | |
- name: look for SmartOS configuration | |
stat: | |
path: /etc/cloud/cloud.cfg.d/90_smartos.cfg | |
register: smartos_cfg | |
- name: Remove /data entry from 90_smartos.cfg | |
blockinfile: | |
path: /etc/cloud/cloud.cfg.d/90_smartos.cfg | |
block: | | |
mounts: | |
- [ vdb, /data, auto, "defaults,nofail" ] | |
state: absent | |
when: smartos_cfg.stat.exists | |
- name: Remove /data entry from fstab | |
mount: | |
src: /dev/vdb | |
path: /data | |
state: absent | |
when: smartos_cfg.stat.exists | |
- name: Look for a tank zpool | |
stat: | |
path: /dev/disk/by-label/tank | |
register: tank_device | |
- name: Create a tank zpool | |
command: | |
cmd: zpool create -f tank /dev/vdb | |
when: smartos_cfg.stat.exists and not tank_device.stat.exists | |
- name: Create tank/data | |
zfs: | |
name: tank/data | |
state: present | |
extra_zfs_properties: | |
mountpoint: /data | |
compression: on | |
when: smartos_cfg.stat.exists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment