Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
#27 add nfs role
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Mar 15, 2016
1 parent cd11eb4 commit 2e888e3
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ansible/roles/nfs/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_exports: []
4 changes: 4 additions & 0 deletions ansible/roles/nfs/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: restart nfs
service: "name={{ nfs_server_daemon }} state=restarted"
when: nfs_exports|length
24 changes: 24 additions & 0 deletions ansible/roles/nfs/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
dependencies: []

galaxy_info:
author: geerlingguy
description: NFS installation for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.0
platforms:
- name: EL
versions:
- all
- name: Fedora
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- system
42 changes: 42 additions & 0 deletions ansible/roles/nfs/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# Include variables and define needed variables.
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"

- name: Include overrides specific to RHEL 7.
include_vars: RedHat-7.yml
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"

- name: Include overrides specific to Fedora.
include_vars: Fedora.yml
when: ansible_os_family == 'RedHat' and ansible_distribution == "Fedora"

# Setup/install tasks.
- include: setup-RedHat.yml
when: ansible_os_family == 'RedHat'

- include: setup-Debian.yml
when: ansible_os_family == 'Debian'

- name: Ensure directories to export exist
file: 'path="{{ item.strip().split()[0] }}" state=directory'
with_items: "{{ nfs_exports }}"
notify: restart nfs

- name: Copy exports file.
template:
src: exports.j2
dest: /etc/exports
owner: root
group: root
mode: 0644
register: nfs_exports_copy
notify: restart nfs

- name: Restart NFS immediately if exports are updated.
service: "name={{ nfs_server_daemon }} state=restarted"
when: nfs_exports_copy.changed

- name: Ensure nfs is running.
service: "name={{ nfs_server_daemon }} state=started enabled=yes"
when: nfs_exports|length
6 changes: 6 additions & 0 deletions ansible/roles/nfs/tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Ensure NFS utilities are installed.
apt: "name={{ item }} state=installed"
with_items:
- nfs-common
- nfs-kernel-server
6 changes: 6 additions & 0 deletions ansible/roles/nfs/tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Ensure NFS utilities are installed.
package: name=nfs-utils state=installed

- name: Ensure rpcbind is running.
service: name=rpcbind state=started enabled=yes
13 changes: 13 additions & 0 deletions ansible/roles/nfs/templates/exports.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
{% for export in nfs_exports %}
{{ export }}
{% endfor %}
1 change: 1 addition & 0 deletions ansible/roles/nfs/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
5 changes: 5 additions & 0 deletions ansible/roles/nfs/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ansible-role-nfs
2 changes: 2 additions & 0 deletions ansible/roles/nfs/vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_server_daemon: nfs-kernel-server
2 changes: 2 additions & 0 deletions ansible/roles/nfs/vars/Fedora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_server_daemon: nfs-server
2 changes: 2 additions & 0 deletions ansible/roles/nfs/vars/RedHat-7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_server_daemon: nfs-server
2 changes: 2 additions & 0 deletions ansible/roles/nfs/vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
nfs_server_daemon: nfs

0 comments on commit 2e888e3

Please sign in to comment.