-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02088b1
commit 63eba1e
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ansible.python.interpreterPath": "/bin/python" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# NFS Server Setup with Ansible 🚀 | ||
|
||
![Ansible](https://img.shields.io/badge/Ansible-Playbook-blue?logo=ansible) | ||
![NFS](https://img.shields.io/badge/NFS-Server-yellowgreen) | ||
|
||
This playbook allows you to set up and configure an NFS server automatically. It supports different Linux distributions such as **RedHat** and **Debian** families. The process includes installing the NFS server, creating a directory, and exporting it to the network. | ||
|
||
## Purpose 🎯 | ||
|
||
- Set up an **NFS (Network File System)** server and enable file sharing over the network. | ||
- Be compatible with both RedHat and Debian-based systems. | ||
- Create an NFS directory, export it, and manage the service. | ||
|
||
## Requirements 📋 | ||
|
||
- Ansible must be installed. | ||
- The `nfs_server` group in your inventory should contain the host(s) that will act as the NFS server. | ||
|
||
## Variables 📂 | ||
|
||
- `nfs_export_path`: The path to the directory you want to share over NFS. | ||
- `nfs_allowed_hosts`: Hosts allowed to access the shared directory. | ||
- `nfs_service_name`: Variable to manage NFS service names for RedHat and Debian families. | ||
|
||
## How to Use ⚙️ | ||
|
||
1. **Prepare an inventory file**, for example: | ||
```ini | ||
[nfs_server] | ||
nfs.example.com ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa | ||
``` | ||
|
||
2. **Run the playbook:** | ||
```bash | ||
ansible-playbook -i inventory nfs_setup.yml | ||
``` | ||
|
||
3. **What the playbook does:** | ||
- Installs required NFS packages. | ||
- Creates the export directory and sets the correct permissions. | ||
- Updates the `/etc/exports` file. | ||
- Starts the NFS service and exports the directory. | ||
|
||
## Testing 🧪 | ||
|
||
1. Check that the NFS service is running on the server: | ||
```bash | ||
systemctl status nfs-server | ||
``` | ||
|
||
2. Verify that the directory is exported: | ||
```bash | ||
exportfs -v | ||
``` | ||
|
||
3. Mount the NFS share from another machine to test: | ||
```bash | ||
mount nfs.example.com:/srv/nfs /mnt | ||
``` | ||
|
||
## Supported OS Families 🖥️ | ||
|
||
- **RedHat** family: RHEL, CentOS, Fedora | ||
- **Debian** family: Debian, Ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
- hosts: nfs_server | ||
become: yes | ||
vars: | ||
nfs_export_path: /srv/nfs | ||
nfs_allowed_hosts: "*" | ||
nfs_service_name: | ||
RedHat: nfs-server | ||
Debian: nfs-kernel-server | ||
|
||
tasks: | ||
- name: Install NFS packages (RedHat) | ||
yum: | ||
name: nfs-utils | ||
state: present | ||
when: ansible_os_family == "RedHat" | ||
|
||
- name: Install NFS packages (Debian) | ||
apt: | ||
name: | ||
- nfs-kernel-server | ||
- nfs-common | ||
state: present | ||
update_cache: yes | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Create NFS export directory | ||
file: | ||
path: "{{ nfs_export_path }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: '0755' | ||
|
||
- name: Configure NFS exports | ||
copy: | ||
content: "{{ nfs_export_path }} {{ nfs_allowed_hosts }}(rw,sync,no_root_squash,no_subtree_check)\n" | ||
dest: /etc/exports | ||
owner: root | ||
group: root | ||
mode: '0644' | ||
|
||
- name: Start and enable NFS service | ||
systemd: | ||
name: "{{ nfs_service_name[ansible_os_family] }}" | ||
enabled: yes | ||
state: started | ||
|
||
- name: Export NFS directories | ||
command: exportfs -ra | ||
notify: restart nfs | ||
|
||
handlers: | ||
- name: restart nfs | ||
systemd: | ||
name: "{{ nfs_service_name[ansible_os_family] }}" | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[nfs_server] | ||
debian ansible_host=142.93.3.181 ansible_user=root | ||
ubuntu ansible_host=104.248.116.57 ansible_user=root | ||
rhel ansible_host=137.184.198.185 ansible_user=root |