diff --git a/ansible/roles/nfs/defaults/main.yml b/ansible/roles/nfs/defaults/main.yml new file mode 100644 index 000000000..256ab353e --- /dev/null +++ b/ansible/roles/nfs/defaults/main.yml @@ -0,0 +1,2 @@ +--- +nfs_exports: [] diff --git a/ansible/roles/nfs/handlers/main.yml b/ansible/roles/nfs/handlers/main.yml new file mode 100644 index 000000000..83b7bcea3 --- /dev/null +++ b/ansible/roles/nfs/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: restart nfs + service: "name={{ nfs_server_daemon }} state=restarted" + when: nfs_exports|length diff --git a/ansible/roles/nfs/meta/main.yml b/ansible/roles/nfs/meta/main.yml new file mode 100644 index 000000000..75967954d --- /dev/null +++ b/ansible/roles/nfs/meta/main.yml @@ -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 diff --git a/ansible/roles/nfs/tasks/main.yml b/ansible/roles/nfs/tasks/main.yml new file mode 100644 index 000000000..da49312f8 --- /dev/null +++ b/ansible/roles/nfs/tasks/main.yml @@ -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 diff --git a/ansible/roles/nfs/tasks/setup-Debian.yml b/ansible/roles/nfs/tasks/setup-Debian.yml new file mode 100644 index 000000000..9c930dfa4 --- /dev/null +++ b/ansible/roles/nfs/tasks/setup-Debian.yml @@ -0,0 +1,6 @@ +--- +- name: Ensure NFS utilities are installed. + apt: "name={{ item }} state=installed" + with_items: + - nfs-common + - nfs-kernel-server diff --git a/ansible/roles/nfs/tasks/setup-RedHat.yml b/ansible/roles/nfs/tasks/setup-RedHat.yml new file mode 100644 index 000000000..18beb5ac9 --- /dev/null +++ b/ansible/roles/nfs/tasks/setup-RedHat.yml @@ -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 diff --git a/ansible/roles/nfs/templates/exports.j2 b/ansible/roles/nfs/templates/exports.j2 new file mode 100644 index 000000000..fa27c5546 --- /dev/null +++ b/ansible/roles/nfs/templates/exports.j2 @@ -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 %} \ No newline at end of file diff --git a/ansible/roles/nfs/tests/inventory b/ansible/roles/nfs/tests/inventory new file mode 100644 index 000000000..2fbb50c4a --- /dev/null +++ b/ansible/roles/nfs/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/ansible/roles/nfs/tests/test.yml b/ansible/roles/nfs/tests/test.yml new file mode 100644 index 000000000..9fe75bcbd --- /dev/null +++ b/ansible/roles/nfs/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible-role-nfs diff --git a/ansible/roles/nfs/vars/Debian.yml b/ansible/roles/nfs/vars/Debian.yml new file mode 100644 index 000000000..d7ee6b5d2 --- /dev/null +++ b/ansible/roles/nfs/vars/Debian.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-kernel-server diff --git a/ansible/roles/nfs/vars/Fedora.yml b/ansible/roles/nfs/vars/Fedora.yml new file mode 100644 index 000000000..05388584e --- /dev/null +++ b/ansible/roles/nfs/vars/Fedora.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-server diff --git a/ansible/roles/nfs/vars/RedHat-7.yml b/ansible/roles/nfs/vars/RedHat-7.yml new file mode 100644 index 000000000..05388584e --- /dev/null +++ b/ansible/roles/nfs/vars/RedHat-7.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs-server diff --git a/ansible/roles/nfs/vars/RedHat.yml b/ansible/roles/nfs/vars/RedHat.yml new file mode 100644 index 000000000..f635f2870 --- /dev/null +++ b/ansible/roles/nfs/vars/RedHat.yml @@ -0,0 +1,2 @@ +--- +nfs_server_daemon: nfs