Code/nas

nas

Ansible role that deployss my nas configuration. It mostly handles nfs configurations and exports that are tailored to the hardware and service configuration.

yannick

README

NAS (Network Attached Storage) Ansible Role

A comprehensive Ansible role for configuring and managing Network Attached Storage (NAS) servers with NFS exports, RAID monitoring, network bonding, and performance optimization.

Features

  • NFS Server Configuration: Complete NFS server setup with selective directory exports
  • RAID Management: mdadm RAID array creation, monitoring, and alerting
  • Network Bonding: Support for bonded network interfaces (LACP/802.3ad)
  • Storage Management: Automated mounting and filesystem management
  • Performance Optimization: Network and storage performance tuning
  • Health Monitoring: Comprehensive system health checks and alerting
  • Security: Secure NFS settings
  • Backup Integration: Automated configuration backups
  • SMART Monitoring: Disk health monitoring with smartmontools

Supported Platforms

  • Debian: 11 (Bullseye), 12 (Bookworm)
  • Ubuntu: 20.04 (Focal), 22.04 (Jammy), 24.04 (Noble)
  • Red Hat Enterprise Linux: 8, 9
  • CentOS: 8, 9, Stream

Requirements

  • Ansible 2.9 or higher
  • Root access (via sudo) on target hosts
  • Network connectivity between Ansible controller and target hosts

Role Variables

Basic NFS Configuration

# 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"

RAID Configuration

# 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"

Network Bonding

# 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 Mounts

# 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"

Performance Tuning

# 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

Monitoring and Alerting

# Enable monitoring
nas_monitoring_enabled: true
nas_smartmontools_enabled: true

# Email notifications for alerts
nas_email_notifications: "[email protected]"

Backup Integration

# 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"

Example Playbooks

Basic NAS Server

---
- 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"

Advanced NAS with RAID5 and Bonding

---
- 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"

Directory Structure

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
│   ├── exports.j2                # NFS exports file
│   ├── mdadm-monitor.j2          # RAID monitoring config
│   ├── nas-logrotate.j2          # Log rotation config
│   └── smartd.conf.j2            # SMART monitoring config
└── vars/
    └── main.yml          # Internal variables

Monitoring and Maintenance

The role sets up basic monitoring via system services:

System Monitoring

  • RAID Monitoring: mdadm monitoring service
  • SMART Monitoring: smartmontools for disk health
  • Service-based: No custom scripts (will be replaced by netdata)

Log Files

  • Main log: /var/log/nas-role.log
  • System info: /var/log/nas-system-info.txt
  • Rotation: Configured via logrotate

Troubleshooting

Common Issues

  1. NFS exports not accessible

    • Verify exports: exportfs -v
    • Test connectivity: showmount -e <nas_ip>
  2. RAID array degraded

    • Check status: cat /proc/mdstat
    • View details: mdadm --detail /dev/md0
    • Monitor logs: tail -f /var/log/nas-role.log
  3. Network bond issues

    • Check bond status: cat /proc/net/bonding/bond0
    • Verify interface states: ip link show
    • Review network config: networkctl status

Log Analysis

# 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

Dependencies

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)

License

MIT

Author Information

Created for personal homelab automation. Contributions and feedback welcome.

For issues or feature requests, please check the project documentation or contact the homelab administrator.

Quick Actions

Browse FilesView Commits
git clone https://rakys.xyz/git/nas.git

Repository Statistics

0
Stars
0
Forks
1
Watchers
0
Issues
Default Branch:main
Primary Language:Jinja
Created:August 31, 2025
Last Updated:October 2, 2025
Repository Size:0.05 KB