home-server/roles/nfs/tasks/main.yml

131 lines
3.1 KiB
YAML

---
# The home-server project produces a multi-purpose setup using Ansible.
# Copyright © 2018 Y. Gablin, under the GPL-3.0-or-later license.
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
### UPSTREAM BEGIN ⇒ ###
- name: pull prerequisites from upstream
include_role: name=etckeeper.inc allow_duplicates=true tasks_from=upstream.yml
vars:
msg: NFS
### ⇐ UPSTREAM BEGIN ###
- name: install packages
package:
name: "{{item}}"
state: present
with_items:
- nfs-utils
- name: create the NFS root
file:
path: /srv/nfs
state: directory
- name: mount the exported directories
mount:
src: '{{item.path}}'
path: '/srv/nfs/{{item.name}}'
state: mounted
fstype: none
opts: 'bind,x-systemd.requires-mounts-for={{item.path}},x-systemd.requires-mounts-for={{("/srv/nfs/" + item.name) | dirname}}'
dump: 0
passno: 0
with_items: "{{nfs_exports}}"
when:
- ((item.path | truncate(8, True, '', 0)) != '/srv/nfs')
notify:
- restart nfs-server.service
- name: set the nfs-server dependencies on the mount points
lineinfile:
path: /etc/systemd/system/nfs-server.service.d/mount-exports.conf
create: true
mode: 0660
line: RequiresMountsFor=/srv/nfs/{{item.name}}
insertafter: EOF
with_items: "{{nfs_exports}}"
when:
- ((item.path | truncate(8, True, '', 0)) != '/srv/nfs')
notify:
- restart nfs-server.service
- name: make the nfs-server dependencies file syntactically correct
lineinfile:
path: /etc/systemd/system/nfs-server.service.d/mount-exports.conf
create: false
line: '[Unit]'
insertbefore: BOF
ignore_errors: true
### UPSTREAM END ⇒ ###
- name: merge upstream
include_role: name=etckeeper.inc allow_duplicates=true tasks_from=merge.yml
vars:
msg: NFS
### ⇐ UPSTREAM END ###
- name: create the exports file
template:
src: templates/exports.j2
dest: /etc/exports.d/{{nickname}}.exports
mode: 0600
notify:
- restart nfs-server.service
- name: set the nfsd settings
blockinfile:
path: /etc/nfs.conf
marker: '# {mark} nfsd'
block: |
port=2049
insertafter: '^\[nfsd\]'
notify:
- restart nfs-server.service
- name: set the statd settings
blockinfile:
path: /etc/nfs.conf
marker: '# {mark} statd'
block: |
port=2050
outgoing-port=2051
insertafter: '^\[statd\]'
notify:
- restart nfs-server.service
- name: set the mountd settings
blockinfile:
path: /etc/nfs.conf
marker: '# {mark} mountd'
block: |
port=2052
insertafter: '^\[mountd\]'
notify:
- restart nfs-server.service
- name: set the lockd settings
blockinfile:
path: /etc/nfs.conf
marker: '# {mark} lockd'
block: |
port=2053
udp-port=2053
insertafter: '^\[lockd\]'
notify:
- restart nfs-server.service
- name: enable nfs-server
systemd:
daemon_reload: true
name: nfs-server.service
enabled: true
### LOCAL COMMIT ⇒ ###
- name: commit local changes
include_role: name=etckeeper.inc allow_duplicates=true tasks_from=local.yml
vars:
msg: NFS
### ⇐ LOCAL COMMIT ###
- meta: flush_handlers