/
/
A comprehensive Ansible role for configuring and managing Network Attached Storage (NAS) servers with NFS exports, RAID monitoring, network bonding, and performance optimization.
# Enable/disable NFS server
nas_nfs_enabled: true
# NFS exports configuration
nas_nfs_exports:
- path: "/mnt/storage/shared"
clients: "192.168.1.0/24"
options: "rw,sync,no_subtree_check,no_root_squash"
- path: "/mnt/storage/media"
clients: "192.168.1.100(rw,sync) 192.168.1.101(ro,sync)"
options: "no_subtree_check"
# Security settings
nas_nfs_secure_ports: true
nas_allowed_networks:
- "192.168.1.0/24"
# Enable RAID support
nas_raid_enabled: true
nas_raid_monitoring: true
# RAID device configuration
nas_raid_devices:
- device: "/dev/md0"
level: "raid5"
members:
- "/dev/sdb1"
- "/dev/sdc1"
- "/dev/sdd1"
mount_point: "/mnt/storage"
filesystem: "ext4"
# Enable network bonding
nas_network_bonding_enabled: true
# Bond configuration
nas_bond_interfaces:
- bond_name: "bond0"
mode: "802.3ad" # LACP
slaves:
- "eth0"
- "eth1"
ip: "192.168.1.100"
netmask: "255.255.255.0"
gateway: "192.168.1.1"
# Storage mount points
nas_storage_mounts:
- device: "/dev/md0"
mount_point: "/mnt/storage"
filesystem: "ext4"
options: "defaults,noatime"
dump: 0
pass: 2
mode: "0755"
owner: "root"
group: "root"
# Enable performance optimizations
nas_performance_tuning_enabled: true
# Network performance settings
nas_tcp_window_scaling: true
nas_tcp_congestion_control: "bbr"
# Custom sysctl settings
nas_sysctl_settings:
net.core.rmem_max: 16777216
net.core.wmem_max: 16777216
vm.dirty_background_ratio: 5
vm.dirty_ratio: 10
# Enable monitoring
nas_monitoring_enabled: true
nas_smartmontools_enabled: true
# Email notifications for alerts
nas_email_notifications: "[email protected]"
# Enable backup of NAS configurations
nas_backup_integration: true
# Paths to include in backups
nas_backup_paths:
- "/mnt/storage/critical"
- "/etc/exports"
- "/etc/mdadm/mdadm.conf"
---
- hosts: nas_servers
become: true
roles:
- role: nas
vars:
nas_nfs_enabled: true
nas_nfs_exports:
- path: "/srv/nfs/shared"
clients: "192.168.1.0/24"
options: "rw,sync,no_subtree_check"
nas_storage_mounts:
- device: "/dev/sdb1"
mount_point: "/srv/nfs/shared"
filesystem: "ext4"
options: "defaults,noatime"
---
- hosts: advanced_nas
become: true
roles:
- role: nas
vars:
# NFS Configuration
nas_nfs_enabled: true
nas_nfs_exports:
- path: "/mnt/raid/shared"
clients: "192.168.1.0/24"
options: "rw,sync,no_subtree_check,no_root_squash"
- path: "/mnt/raid/media"
clients: "192.168.1.0/24"
options: "ro,sync,no_subtree_check"
# RAID Configuration
nas_raid_enabled: true
nas_raid_monitoring: true
nas_raid_devices:
- device: "/dev/md0"
level: "raid5"
members:
- "/dev/sdb"
- "/dev/sdc"
- "/dev/sdd"
mount_point: "/mnt/raid"
filesystem: "ext4"
# Network Bonding
nas_network_bonding_enabled: true
nas_bond_interfaces:
- bond_name: "bond0"
mode: "802.3ad"
slaves:
- "enp1s0"
- "enp2s0"
ip: "192.168.1.100"
netmask: "255.255.255.0"
gateway: "192.168.1.1"
# Monitoring
nas_monitoring_enabled: true
nas_email_notifications: "[email protected]"
nas_performance_tuning_enabled: true
# Security
nas_allowed_networks:
- "192.168.1.0/24"
- "10.0.0.0/8"
roles/nas/
âââ README.md
âââ defaults/
â âââ main.yml # Default variables
âââ handlers/
â âââ main.yml # Service handlers
âââ meta/
â âââ main.yml # Role metadata
âââ tasks/
â âââ main.yml # Main task orchestration
â âââ backup.yml # Backup configuration
â âââ bonding.yml # Network bonding setup
â âââ monitoring.yml # Health monitoring setup
â âââ mounts.yml # Storage mounting
â âââ nfs.yml # NFS server configuration
â âââ performance.yml # Performance tuning
â âââ raid.yml # RAID management
âââ templates/
â âââ bond-interface.j2 # Bond interface config
â âââ bond-network.j2 # Bond network config
â âââ bond-slave.j2 # Bond slave config
â âââ collect-nas-info.sh.j2 # System info script
â âââ exports.j2 # NFS exports file
â âââ mdadm-monitor.j2 # RAID monitoring config
â âââ nas-backup.sh.j2 # Backup script
â âââ nas-logrotate.j2 # Log rotation config
â âââ nas-monitor.sh.j2 # Health monitoring script
â âââ nas-performance-monitor.sh.j2 # Performance monitoring
â âââ smartd.conf.j2 # SMART monitoring config
âââ vars/
âââ main.yml # Internal variables
The role sets up several monitoring mechanisms:
/usr/local/bin/nas-monitor.sh
/usr/local/bin/nas-performance-monitor.sh
/usr/local/bin/nas-backup.sh
/var/log/nas-role.log
/var/log/nas-system-info.txt
NFS exports not accessible
exportfs -v
showmount -e <nas_ip>
RAID array degraded
cat /proc/mdstat
mdadm --detail /dev/md0
tail -f /var/log/nas-role.log
Network bond issues
cat /proc/net/bonding/bond0
ip link show
networkctl status
# Monitor NAS health in real-time
tail -f /var/log/nas-role.log
# Check RAID events
journalctl -u mdmonitor -f
# Monitor NFS activity
journalctl -u nfs-kernel-server -f
# Check network interface status
journalctl -u systemd-networkd -f
This role has no external role dependencies but requires the following system packages (automatically installed):
nfs-kernel-server
/ nfs-utils
nfs-common
mdadm
smartmontools
hdparm
ifenslave
(for bonding on Debian/Ubuntu)MIT
Created for personal homelab automation. Contributions and feedback welcome.
For issues or feature requests, please check the project documentation or contact the homelab administrator.