Skip to content

Instantly share code, notes, and snippets.

Created November 11, 2017 19:42
Show Gist options
  • Save anonymous/9b9d9236f97eed5ea792f33354dcf659 to your computer and use it in GitHub Desktop.
Save anonymous/9b9d9236f97eed5ea792f33354dcf659 to your computer and use it in GitHub Desktop.
- hosts: localhost
vars_files:
- vars.yml
tasks:
- name: install zfsutils-linux
apt:
name: zfsutils-linux
state: installed
become: true
- name: check if pool has been created
shell: sudo zpool status pool0
register: pool0_created
ignore_errors: True
- name: create pool0
shell: sudo zpool create -f pool0 /dev/sdb
when: pool0_created|failed
- name: install nfs server packages
apt:
name: nfs-kernel-server
state: installed
become: true
- name: add mount path to /etc/exports
lineinfile:
path: /etc/exports
line: "{{ export_path }} {{ nfs_client_subnet }}(rw,sync,no_subtree_check,all_squash,anonuid={{ anonuid }},anongid={{ anongid }})"
register: exports_written
become: true
- name: create zfs filesystem
zfs:
name: "{{ zfs_dataset }}"
state: present
become: true
- name: gather zfs facts
zfs_facts:
dataset: "{{ zfs_dataset }}"
type: filesystem
become: true
- name: check if zfs dataset is mounted
fail:
msg: "{{ zfs_dataset }} not mounted"
with_items: "{{ ansible_zfs_datasets }}"
when: item.name == zfs_dataset and item.mounted != "yes"
become: true
- name: create mount path directory
file:
path: "{{ export_path }}"
state: directory
recurse: yes
become: true
- name: set permissions on /export
file:
path: /export
state: directory
recurse: yes
owner: "{{ anongid }}"
group: "{{ anongid }}"
mode: 0755
become: true
- name: export filesystem
command: /usr/sbin/exportfs -a
when: exports_written.changed
become: true
- hosts: nfs_clients
vars_files:
- vars.yml
tasks:
- name: install nfs client packages
apt:
name: nfs-common
state: installed
become: true
- name: create mount path
file:
path: "{{ mount_path }}"
state: directory
mode: 0755
become: true
- name: mount nfs filesystem
mount:
path: "{{ mount_path}}"
src: "{{ nfs_server_host }}:{{ export_path }}"
fstype: nfs
opts: "{{ mount_options }}"
state: mounted
become: true
- name: make /data
file:
state: directory
path: "{{ link_dirname }}"
become: true
- name: make symlink to /data/homes
file:
path: "{{ link_dirname }}/{{ link_basename }}"
src: "{{ mount_path }}"
state: link
become: true
# we are not using kerberos; may improve performance
- name: blacklist rpc gss kernel modules
kernel_blacklist:
name: "{{ item }}"
state: present
with_items:
- "rpcsec_gss_krb5"
- "auth_rpcgss"
become: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment