Samba server Ansible role https://www.samba.org/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Conrad b06e46367e
All checks were successful
Lint + Tag / format (push) Successful in 8s
Lint + Tag / tag (push) Successful in 6s
feat: added force_user and force_group for shares
2026-11-10 14:58:15 +01:00
.forgejo/workflows fix: moved to forgejo pipeline 2026-10-14 14:37:04 +07:00
defaults feat: added force_user and force_group for shares 2026-11-10 14:58:15 +01:00
handlers feat: initial version 2026-05-10 12:09:16 +02:00
meta feat: initial version 2026-05-10 12:09:16 +02:00
tasks fix: fixed minor issues 2026-05-10 12:54:02 +02:00
templates feat: added force_user and force_group for shares 2026-11-10 14:58:15 +01:00
.gitignore feat: initial version 2026-05-10 12:09:16 +02:00
CHANGELOG.md feat: added force_user and force_group for shares 2026-11-10 14:58:15 +01:00
LICENSE feat: initial version 2026-05-10 12:09:16 +02:00
README.md feat: added force_user and force_group for shares 2026-11-10 14:58:15 +01:00

Samba

Deploys a Samba file server with SMB2/3 shares accessible over local network or VPN.

Requirements

None beyond Ansible built-ins.

Variables

Variable Default Description
smb_workgroup WORKGROUP NetBIOS workgroup name shown to Windows clients.
smb_allowed_networks RFC1918 + loopback Networks allowed to connect. All other sources are denied. See Access Control.
smb_sendfile false Enables zero-copy reads via sendfile(). Improves throughput on ext4/XFS. Do not enable on ZFS.
smb_shares [] Shares to export. See Shares below.
smb_users [] System and Samba users to create. See Users below.
smb_uninstall false Stops and disables smbd and removes the samba package.

Usage

Minimal — a single public share (any authenticated user):

smb_shares:
  - name: media
    path: /data/media

With users and per-share access control:

smb_shares:
  - name: media
    path: /data/media
    valid_users: "@media"
    comment: "Media files"
  - name: backup
    path: /data/backup
    valid_users: "@backup"
    read_only: false

smb_users:
  - name: alice
    password: "{{ vault_alice_smb_pass }}"

Shares

Each entry in smb_shares requires name and path. The path must already exist on the host.

Key Default Description
name — Share name as shown to clients. Required.
path — Absolute path on the host. Required.
valid_users (none) Restrict access to a user or group. Prefix group names with @.
read_only false Set to true for a read-only share.
browseable true Set to false to hide the share from network browsers.
comment (none) Description shown to clients.
create_mask 0664 Permission mask applied to new files.
directory_mask 0775 Permission mask applied to new directories.
force_user (none) Write every file as this user, e.g. www-data for Nextcloud.
force_group (none) Write every file with this group.

Users

Each entry in smb_users creates a system account (no login shell, no home directory) and registers it in the Samba password database. Passwords are written once on first provision and not updated on subsequent runs.

smb_users:
  - name: alice
    password: "{{ vault_alice_smb_pass }}"

Store passwords in Ansible Vault.

Access Control

The default smb_allowed_networks covers loopback and all RFC1918 ranges:

smb_allowed_networks:
  - "127.0.0.1"
  - "192.168.0.0/16"
  - "10.0.0.0/8"
  - "172.16.0.0/12"

All other sources are denied at the application level. Restrict further by replacing this list with your specific LAN subnet and VPN range.

Uninstall

To stop smbd and remove the samba package:

smb_uninstall: true

Share paths and their data are never removed by this role.

Notes

  • Only SMB2 and SMB3 are enabled — SMB1 is disabled (EternalBlue/WannaCry vector).
  • NetBIOS is disabled. Only TCP port 445 is used.
  • SMB signing is mandatory, preventing MITM and relay attacks. All modern Windows, macOS, and Linux clients support this.
  • Share paths must exist on the host before the role runs. The role does not create them. Every parent directory in the path must also be traversable (execute bit) by the Samba user — a common gotcha with ZFS pool layouts where the pool root (/pool) is mode 750.
  • Do not enable smb_sendfile on ZFS — it bypasses the ARC cache and causes a measurable performance regression.