From b58f5d49053388e51a749b3c386a171d38fc124b Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Mon, 26 May 2025 21:32:55 +0100 Subject: [PATCH] wip: add nfs_client role --- roles/nfs_client/README.md | 22 ++++++++++++++++++++++ roles/nfs_client/defaults/main.yaml | 2 ++ roles/nfs_client/handlers/main.yaml | 1 + roles/nfs_client/tasks/configure.yaml | 20 ++++++++++++++++++++ roles/nfs_client/tasks/install.yaml | 7 +++++++ roles/nfs_client/tasks/main.yaml | 9 +++++++++ roles/nfs_client/tasks/preflight.yaml | 3 +++ roles/nfs_client/vars/Debian.yaml | 2 ++ 8 files changed, 66 insertions(+) create mode 100644 roles/nfs_client/README.md create mode 100644 roles/nfs_client/defaults/main.yaml create mode 100644 roles/nfs_client/handlers/main.yaml create mode 100644 roles/nfs_client/tasks/configure.yaml create mode 100644 roles/nfs_client/tasks/install.yaml create mode 100644 roles/nfs_client/tasks/main.yaml create mode 100644 roles/nfs_client/tasks/preflight.yaml create mode 100644 roles/nfs_client/vars/Debian.yaml diff --git a/roles/nfs_client/README.md b/roles/nfs_client/README.md new file mode 100644 index 0000000..60ea47b --- /dev/null +++ b/roles/nfs_client/README.md @@ -0,0 +1,22 @@ +# Ansible Role - `epcc.nfs_client` + +Install and configure an NFS client. + +## Role Variables + +| Variable | Description | Type | Default | +| ----------------- | -------------------------------- | ---- | ----------------------- | +| nfs_client_mounts | A list of mount points to enable | list | `[]` (empty, no mounts) | + +Example configuration: + +```yaml +nfs_client_mounts: + - src: "127.0.0.1:/var/nfs/safe_data" + path: "/safe_data" + opts: "defaults,timeo=900,retrans=5,_netdev" +``` + +## Supported Platforms + +This role has been tested with Ubuntu 22.04 only. diff --git a/roles/nfs_client/defaults/main.yaml b/roles/nfs_client/defaults/main.yaml new file mode 100644 index 0000000..edcf5bb --- /dev/null +++ b/roles/nfs_client/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +nfs_client_mounts: [] diff --git a/roles/nfs_client/handlers/main.yaml b/roles/nfs_client/handlers/main.yaml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/nfs_client/handlers/main.yaml @@ -0,0 +1 @@ +--- diff --git a/roles/nfs_client/tasks/configure.yaml b/roles/nfs_client/tasks/configure.yaml new file mode 100644 index 0000000..24cadc3 --- /dev/null +++ b/roles/nfs_client/tasks/configure.yaml @@ -0,0 +1,20 @@ +--- +- name: Ensure mountpoint exists + become: true + loop: "{{ nfs_client_mounts }}" + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + owner: root + group: root + mode: u=rwx,g=rx,o=rx + +- name: Ensure exports are mounted + become: true + loop: "{{ nfs_client_mounts }}" + ansible.posix.mount: + src: "{{ item.src }}" + path: "{{ item.path }}" + opts: "{{ item.opts }}" + state: mounted + type: nfs diff --git a/roles/nfs_client/tasks/install.yaml b/roles/nfs_client/tasks/install.yaml new file mode 100644 index 0000000..5149680 --- /dev/null +++ b/roles/nfs_client/tasks/install.yaml @@ -0,0 +1,7 @@ +--- +- name: Ensure NFS client package is present + become: true + ansible.builtin.package: + name: "{{ __nfs_client_package }}" + state: present + update_cache: true diff --git a/roles/nfs_client/tasks/main.yaml b/roles/nfs_client/tasks/main.yaml new file mode 100644 index 0000000..140d834 --- /dev/null +++ b/roles/nfs_client/tasks/main.yaml @@ -0,0 +1,9 @@ +--- +- name: Import preflight tasks + ansible.builtin.import_tasks: preflight.yaml + +- name: Import install tasks + ansible.builtin.import_tasks: install.yaml + +- name: Import configure tasks + ansible.builtin.import_tasks: configure.yaml diff --git a/roles/nfs_client/tasks/preflight.yaml b/roles/nfs_client/tasks/preflight.yaml new file mode 100644 index 0000000..a229e1c --- /dev/null +++ b/roles/nfs_client/tasks/preflight.yaml @@ -0,0 +1,3 @@ +--- +- name: Include OS-specific variables + ansible.builtin.include_vars: "{{ ansible_os_family }}.yaml" diff --git a/roles/nfs_client/vars/Debian.yaml b/roles/nfs_client/vars/Debian.yaml new file mode 100644 index 0000000..6a64637 --- /dev/null +++ b/roles/nfs_client/vars/Debian.yaml @@ -0,0 +1,2 @@ +--- +__nfs_client_package: nfs-common -- GitLab