From 0c06b423472eb04ccf40db5ba3f47eaa6130f2db Mon Sep 17 00:00:00 2001 From: moritzrfs Date: Mon, 5 May 2025 19:59:39 +0200 Subject: [PATCH] Initial commit --- inventory | 5 +++++ nfs.yaml | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vars.yaml | 11 +++++++++++ 3 files changed, 72 insertions(+) create mode 100644 inventory create mode 100644 nfs.yaml create mode 100644 vars.yaml diff --git a/inventory b/inventory new file mode 100644 index 0000000..891a64a --- /dev/null +++ b/inventory @@ -0,0 +1,5 @@ +[nfs_servers] +share-box.home ansible_user=ansible ansible_ssh_private_key_file=/home/moritz/ansible/keys/ansible + +[nfs_clients] +pve03.home ansible_user=ansible ansible_ssh_private_key_file=/home/moritz/ansible/keys/ansible \ No newline at end of file diff --git a/nfs.yaml b/nfs.yaml new file mode 100644 index 0000000..e09d8d0 --- /dev/null +++ b/nfs.yaml @@ -0,0 +1,56 @@ +# nfs.yaml + +- name: Setup NFS Server + hosts: nfs_servers + become: true + vars_files: + - vars.yaml + tasks: + - name: Install NFS server + apt: + name: nfs-kernel-server + state: present + + - name: Create export directories + file: + path: "{{ item.path }}" + state: directory + loop: "{{ nfs_exports }}" + + - name: Ensure NFS export entry is present (append only) + lineinfile: + path: /etc/exports + line: >- + {{ item.path }} {{ item.clients | map(attribute='name') | zip(item.clients | map(attribute='options')) | map('join', '(') | map('regex_replace', '$', ')') | join(' ') }} + create: yes + state: present + loop: "{{ nfs_exports }}" + + - name: Reload NFS exports + command: exportfs -ra + +- name: Setup NFS Client + hosts: nfs_clients + become: true + vars_files: + - vars.yaml + tasks: + - name: Install NFS client + apt: + name: nfs-common + state: present + + - name: Create mount directories + file: + path: "{{ item.path }}" + state: directory + loop: "{{ nfs_mounts }}" + + - name: Mount NFS shares + mount: + path: "{{ item.path }}" + src: "{{ item.src }}" + fstype: nfs + opts: rw + state: mounted + loop: "{{ nfs_mounts }}" \ No newline at end of file diff --git a/vars.yaml b/vars.yaml new file mode 100644 index 0000000..86b6268 --- /dev/null +++ b/vars.yaml @@ -0,0 +1,11 @@ +nfs_exports: + - path: /mnt/shares/test + clients: + - name: pve03.home + options: rw,sync,no_subtree_check,no_root_squash + - name: pve02.home + options: rw,sync,no_subtree_check,no_root_squash + +nfs_mounts: + - src: share-box.home:/mnt/shares/test + path: /mnt/test \ No newline at end of file