Skip to content

Commit 6478a91

Browse files
committed
initial commit
0 parents  commit 6478a91

File tree

9 files changed

+848
-0
lines changed

9 files changed

+848
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
zfs_dataset.iml
2+
.idea

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
language: python
3+
python: "2.7"
4+
5+
# Use the new container infrastructure
6+
sudo: false
7+
8+
# Install ansible
9+
addons:
10+
apt:
11+
packages:
12+
- python-pip
13+
14+
install:
15+
# Install ansible
16+
- pip install ansible
17+
18+
# Check ansible version
19+
- ansible --version
20+
21+
# Create ansible.cfg with correct roles_path
22+
- printf '[defaults]\nroles_path=../' >ansible.cfg
23+
24+
script:
25+
# Basic role syntax check
26+
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
27+
28+
notifications:
29+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Ansible ZFS Encrypted Dataset Playbook
2+
3+
This playbook and role allows you to define a list of encrypted ZFS datasets.
4+
5+
I used this on my proxmox setup, but it should be available
6+
to use in all ZFS environments.
7+
8+
Clone this repo into your roles directory:
9+
10+
```
11+
git clone [email protected]:BojanZelic/ansible-zfs-encrypted-datasets.git roles/zfs_datasets
12+
```
13+
14+
Add it to your play's roles:
15+
```
16+
- hosts: all
17+
roles:
18+
- role: bojanzelic.zfs_datasets
19+
zfs_key: "{{ lookup('env','ZFS_KEY') }}"
20+
zfs_datasources:
21+
rpool:
22+
state: present
23+
rpool/backups:
24+
encrypted: true
25+
extra_zfs_properties:
26+
sharenfs: [email protected]/24
27+
rpool/documents:
28+
encrypted: true
29+
rpool/personal_media:
30+
state: present
31+
rpool/media:
32+
state: present
33+
```
34+
35+
Encryption works by loading the encryption key to zfs. The playbook then tries to mount
36+
the dataset.
37+
38+
Because it's encrypted... when you reboot the server, you'll need to run the
39+
playbook to mount the dataset again.

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
defaults:
3+
zfs_key: "{{ lookup('env','ZFS_KEY') | trim}}"
4+
encrypted: false
5+
state: present
6+
mounted: true

meta/main.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
galaxy_info:
2+
author: Bojan Zelic
3+
description: create & mount encrypted zfs datasets
4+
5+
# If the issue tracker for your role is not on github, uncomment the
6+
# next line and provide a value
7+
# issue_tracker_url: http://example.com/issue/tracker
8+
9+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
10+
# - BSD-3-Clause (default)
11+
# - MIT
12+
# - GPL-2.0-or-later
13+
# - GPL-3.0-only
14+
# - Apache-2.0
15+
# - CC-BY-4.0
16+
license: GPL-3.0-only
17+
18+
min_ansible_version: 2.1
19+
20+
# If this a Container Enabled role, provide the minimum Ansible Container version.
21+
# min_ansible_container_version:
22+
23+
#
24+
# Provide a list of supported platforms, and for each platform a list of versions.
25+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
26+
# To view available platforms and versions (or releases), visit:
27+
# https://galaxy.ansible.com/api/v1/platforms/
28+
#
29+
# platforms:
30+
# - name: Fedora
31+
# versions:
32+
# - all
33+
# - 25
34+
# - name: SomePlatform
35+
# versions:
36+
# - all
37+
# - 1.0
38+
# - 7
39+
# - 99.99
40+
41+
galaxy_tags: ['zfs', 'dataset', 'encrypted']
42+
# List tags for your role here, one per line. A tag is a keyword that describes
43+
# and categorizes the role. Users find roles by searching for tags. Be sure to
44+
# remove the '[]' above, if you add tags to this list.
45+
#
46+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
47+
# Maximum 20 tags per role.
48+
49+
dependencies: []
50+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
51+
# if you add dependencies to this list.
52+

tasks/main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
- name: 'Create Encrypted Datasets containers'
3+
shell: echo {{ item.value.zfs_key | default(defaults.zfs_key) }} | /sbin/zfs create -o encryption=on -o keyformat=passphrase {{ item.key }}
4+
register: result
5+
changed_when: result.rc == 0
6+
failed_when:
7+
- result.rc != 0
8+
- '"dataset already exists" not in result.stderr'
9+
with_dict: "{{ zfs_datasources }}"
10+
when: item.value.encrypted | default(defaults.encrypted)
11+
no_log: true
12+
13+
- name: 'Load Encryption key for Encrypted Datasets'
14+
shell: echo {{ item.value.zfs_key | default(defaults.zfs_key) }} | /sbin/zfs load-key {{ item.key }}
15+
register: result
16+
changed_when: result.rc == 0
17+
failed_when:
18+
- result.rc != 0
19+
- '"Key already loaded" not in result.stderr'
20+
with_dict: "{{ zfs_datasources }}"
21+
when: item.value.encrypted | default(defaults.encrypted)
22+
no_log: true
23+
24+
- name: Ensure additional properties for datasets
25+
zfs:
26+
name: "{{ item.key }}"
27+
state: "{{ item.value.state | default(defaults.state) }}"
28+
extra_zfs_properties: "{{ item.value.extra_zfs_properties | default({}) }}"
29+
with_dict: "{{ zfs_datasources }}"
30+
31+
- name: Ensure datasets are mounted
32+
shell: /sbin/zfs mount {{ item.key }}
33+
register: result
34+
changed_when: result.rc == 0
35+
failed_when:
36+
- result.rc != 0
37+
- '"filesystem already mounted" not in result.stderr'
38+
with_dict: '{{ zfs_datasources }}'
39+
when: item.value.mounted | default(defaults.mounted)

tests/inventory

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
localhost
2+

tests/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- hosts: localhost
3+
remote_user: root
4+
roles:
5+
- zfs_dataset

0 commit comments

Comments
 (0)