diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..9d14cfb2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ansible.python.interpreterPath": "/bin/python" +} \ No newline at end of file diff --git a/Ansible/nfs/README.md b/Ansible/nfs/README.md new file mode 100644 index 00000000..34094447 --- /dev/null +++ b/Ansible/nfs/README.md @@ -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 \ No newline at end of file diff --git a/Ansible/nfs/install.yml b/Ansible/nfs/install.yml new file mode 100644 index 00000000..105a2010 --- /dev/null +++ b/Ansible/nfs/install.yml @@ -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 \ No newline at end of file diff --git a/Ansible/nfs/inventory.ini b/Ansible/nfs/inventory.ini new file mode 100644 index 00000000..3bf685ad --- /dev/null +++ b/Ansible/nfs/inventory.ini @@ -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 \ No newline at end of file