From ce73aab536e5cf3b91a2305e2f292627d157892b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 17 Dec 2024 05:38:20 +0100 Subject: add nfs role --- roles/nfs/README.md | 2 ++ roles/nfs/defaults/main.yml | 5 +++++ roles/nfs/handlers/main.yml | 4 ++++ roles/nfs/tasks/main.yml | 26 ++++++++++++++++++++++++++ roles/nfs/templates/exports.j2 | 11 +++++++++++ 5 files changed, 48 insertions(+) create mode 100644 roles/nfs/README.md create mode 100644 roles/nfs/defaults/main.yml create mode 100644 roles/nfs/handlers/main.yml create mode 100644 roles/nfs/tasks/main.yml create mode 100644 roles/nfs/templates/exports.j2 (limited to 'roles/nfs') diff --git a/roles/nfs/README.md b/roles/nfs/README.md new file mode 100644 index 0000000..b26e8e7 --- /dev/null +++ b/roles/nfs/README.md @@ -0,0 +1,2 @@ +This role installs the NFS server & configures a mount. It doesn't support +multiple mounts or anything like that. diff --git a/roles/nfs/defaults/main.yml b/roles/nfs/defaults/main.yml new file mode 100644 index 0000000..0308c64 --- /dev/null +++ b/roles/nfs/defaults/main.yml @@ -0,0 +1,5 @@ +#nfs_dir: +nfs_opts: +nfs_all_squash: false +#nfs_anonuid: +#nfs_anongid: diff --git a/roles/nfs/handlers/main.yml b/roles/nfs/handlers/main.yml new file mode 100644 index 0000000..e92820d --- /dev/null +++ b/roles/nfs/handlers/main.yml @@ -0,0 +1,4 @@ +- name: Reload NFS mounts + become: true + ansible.builtin.command: /usr/sbin/exportfs -arv + listen: nfs_configured diff --git a/roles/nfs/tasks/main.yml b/roles/nfs/tasks/main.yml new file mode 100644 index 0000000..f8045e3 --- /dev/null +++ b/roles/nfs/tasks/main.yml @@ -0,0 +1,26 @@ +- name: Install NFS + become: true + ansible.builtin.package: + name: nfs-server + state: present + +- name: Enable & start NFS service + become: true + ansible.builtin.systemd_service: + name: nfs-server + enabled: true + state: started + +- name: Collect required info + ansible.builtin.setup: + gather_subset: [user] + +- name: Configure NFS + become: true + ansible.builtin.template: + src: exports.j2 + dest: /etc/exports + owner: root + group: root + mode: '644' + notify: nfs_configured diff --git a/roles/nfs/templates/exports.j2 b/roles/nfs/templates/exports.j2 new file mode 100644 index 0000000..301bb45 --- /dev/null +++ b/roles/nfs/templates/exports.j2 @@ -0,0 +1,11 @@ +{% set _opts = 'rw,sync,insecure,no_subtree_check' %} +{% if nfs_opts %} + {% set _opts %}{{ _opts }},{{ nfs_opts }}{% endset %} +{% endif %} +{% if nfs_all_squash %} + {% set _anonuid = nfs_anonuid if nfs_anonuid is defined else ansible_facts['user_uid'] %} + {% set _anongid = nfs_anongid if nfs_anongid is defined else ansible_facts['user_gid'] %} + {% set _opts %}{{ _opts }},all_squash,anonuid={{ _anonuid }},anongid={{ _anongid }}{% endset %} +{% endif %} + +{{ nfs_dir }} *({{ _opts }}) -- cgit v1.2.3