Configures mounting of samba shares on a client with systemd.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-03-28 20:35:59 +01:00
defaults First NetworkManager dispatcher implementation 2024-08-21 22:03:49 +02:00
handlers Restart NetworkManager on dispatcher script change 2024-08-27 21:01:14 +02:00
meta Restart NetworkManager on dispatcher script change 2024-08-27 21:01:14 +02:00
tasks Update assert rules 2026-03-28 20:35:59 +01:00
templates Replace hyphens in systemd.mount with escape code 2024-08-28 14:55:28 +02:00
vars First NetworkManager dispatcher implementation 2024-08-21 22:03:49 +02:00
.gitignore Initial commit 2024-08-21 06:04:33 +02:00
LICENSE Initial commit 2024-08-21 06:04:33 +02:00
README.md Fix typo (singular instead of plural) 2024-08-28 15:13:17 +02:00

Ansible Role: sambaclient

This role configures mounting of samba shares on a client with systemd units and optionally binds them to a specific network.

Features

  • Create a systemd.mount unit per Samba share.
  • Configures corresponding systemd.automount units.
  • Optionally bind the units (with the Samba shares) to a specific network.
  • Manage credential files under /etc/samba/credentials for cifs credentials= mount option.

Limitations

Requirements

Role Variables

External Variables

Public Role Variables

  • sambaclient_credentials (list of dictionaries), default []. Contains credentials for Samba shares. For every entry one file in the credentials directory (see sambaclient_credentials_dir) will be created. These can be specified in the cifs mount option credentials=. The dictionary keys comply with the samba_shares variable from the Ansible collection - vladgh.samba. This enables re-use of already existing definitions. Following keys are expected:
    • name (string), mandatory to add. The user name of the Samba user. This will also be the name of the file in the credentials directory.
    • password (string), mandatory to add. The corresponding password for the Samba user. Should be encrypted with Ansible vault.
  • sambaclient_nm_con_uuid (string), default null. The UUID of the network, where the shares are accessible. Mandatory to set if sambaclient_nm_use_dispatcher is set to true. The connection UUID can be obtained by the command nmcli con show.
  • sambaclient_nm_dispatcher_script_basename (string), default "30-cifs-mounts.sh". The basename of the dispatcher script. Will be appended to sambaclient_nm_dispatcher_dir. This variable should only be changed if there is a actual reason, for example to sort the executions of multiple scripts.
  • sambaclient_nm_use_dispatcher (boolean), default true. Controls whether a NetworkManager dispatcher script should be placed or not. When setting this to false it will delete previously scripts. (But only if sambaclient_nm_dispatcher_script_basename didn't changed in the meantime.)
  • sambaclient_print_template_diff (boolean), default true. Whether the templating tasks should print a diff or not, regardless of the --diff command line option.
  • sambaclient_shares (list of dictionaries), default []. Contains a list of shared to be set up on a host. The following dictionary values are available:
    • src (required): Full address path of a SMB share, e. g. //nas.internal/pictures. The first two characters need to be //. However, a trailing / is not allowed. This is checked in an early stage by the role and it will fail if one src contains a faulty value.
    • path (required): Mount point on the target host. Need to be an absolute path starting with /. Must not have a trailing /.
    • options (optional): List of strings specifying mount options to be appended.

Internal Role Variables

  • sambaclient_credentials_dir, value /etc/samba/credentials. The directory where credential files for the mount option credentials= are kept. This directory path is needed in several locations and exist primarily to avoid typos.
  • sambaclient_nm_dispatcher_dir, value /etc/NetworkManager/dispatcher.d. The directory where NetworkManager dispatcher scripts reside.
  • sambaclient_sd_system_dir, value /etc/systemd/system. The directory where the systemd system units need to be placed.

Tags

To simplify the testing of this role, all tasks are tagged. See the Ansible documentation on Tags for reference. The following tags are available:

  • checks: Added to all tasks that perform checks or gather information for subsequent checks. This tag contains a superset of tasks whose tag begins with checks-.
  • checks-syntax: Added only to tasks that perform simple syntax checks on variables, such as whether they are defined and have the correct data type.
  • checks-host-config: Added to tasks that verify that the host configuration meets the requirements of this role for further configuration.
  • configure: Added to tasks that actually make or prepare changes on the target host.

Dependencies

None.

Example Playbook

Group configuration (group_vars/end_devices/main.yaml):

# TODO: Add real example!
sambaclient_examples:
  - name: bar
    owner: foo
    group: foo

Playbook (playbook.yaml):

- name: Configure Samba Clients
  hosts: end_devices
  tasks:
    - name: Include role sambaclient
      ansible.builtin.include_role:
        name: sambaclient

Pre-Check Variable Syntax

In a larger playbook, it may be desirable to check variable syntax at an early stage. This prevents the playbook from aborting in the middle of a run. Two files are provided for this purpose:

For example, the following task can be added at the desired position in the playbook to perform the syntax checks separately:

- name: Include sambaclient role variable syntax checks
  ansible.builtin.include_role:
    name: sambaclient
    tasks_from: checks-syntax.yaml

License

UNLICENSE

Author Information

lingling