Initial commit
This commit is contained in:
5
inventory
Normal file
5
inventory
Normal file
@@ -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
|
||||||
56
nfs.yaml
Normal file
56
nfs.yaml
Normal file
@@ -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 }}"
|
||||||
11
vars.yaml
Normal file
11
vars.yaml
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user