Configures mounting of samba shares on a client with systemd.
- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| defaults | ||
| handlers | ||
| meta | ||
| tasks | ||
| templates | ||
| vars | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
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/credentialsfor cifscredentials=mount option.
Limitations
Requirements
- Already existing Samba shares accessible from the host.
- Binding to a specific network requires NetworkManager and especially NetworkManager-dispatcher.
- Users and groups need to exist.
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 (seesambaclient_credentials_dir) will be created. These can be specified in the cifs mount optioncredentials=. The dictionary keys comply with thesamba_sharesvariable 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), defaultnull. The UUID of the network, where the shares are accessible. Mandatory to set ifsambaclient_nm_use_dispatcheris set totrue. The connection UUID can be obtained by the commandnmcli con show.sambaclient_nm_dispatcher_script_basename(string), default"30-cifs-mounts.sh". The basename of the dispatcher script. Will be appended tosambaclient_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), defaulttrue. Controls whether a NetworkManager dispatcher script should be placed or not. When setting this to false it will delete previously scripts. (But only ifsambaclient_nm_dispatcher_script_basenamedidn't changed in the meantime.)sambaclient_print_template_diff(boolean), defaulttrue. Whether the templating tasks should print a diff or not, regardless of the--diffcommand 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 onesrccontains 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 optioncredentials=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 withchecks-.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:
- checks-syntax.yaml: Checks the syntax of role variables.
- checks-host-config.yaml: Checks the host configuration.
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