Ansible role for installing and configuring the NFS client
- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
All checks were successful
ci/woodpecker/push/linting Pipeline was successful
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> |
||
| .woodpecker | ||
| meta | ||
| tasks | ||
| templates/systemd | ||
| .ansible-lint | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .markdownlint-cli2.jsonc | ||
| .sops.yaml | ||
| .yamllint | ||
| ansible.cfg | ||
| readme.md | ||
| renovate.json | ||
Ansible Role: NFS Client
Installs the NFS client and mounts NFS shares as systemd .mount units.
Requirements
Debian-family hosts (the install task uses apt and is guarded by os_family == "Debian"). The role needs root and
a systemd-based host.
Dependencies
None (dependencies: []).
Variables
The role has no defaults/main.yaml. All configuration is the nfs_mount list, which has no default and must be
defined (the role loops over it unconditionally).
| Variable | Required | Default | Description |
|---|---|---|---|
nfs_mount |
Yes | none | List of NFS mounts to configure |
Mount keys
| Key | Required | Default | Description |
|---|---|---|---|
nfs_host |
Yes | NFS server hostname or IP | |
nfs_dir |
Yes | Exported directory on the NFS server | |
local_dir_path |
Yes | Local mount point | |
nfs_opts |
Yes | Mount options | |
nfs_fstype |
No | nfs4 |
Filesystem type |
local_dir_owner |
No | root |
Owner of the local mount point |
local_dir_group |
No | root |
Group of the local mount point |
local_dir_mode |
No | 0775 |
Mode of the local mount point |
before_service |
No | List of systemd services that must start after this mount |
Example
nfs_mount:
# production share
- nfs_host: "10.0.0.10"
nfs_dir: "/srv/nfs/production"
local_dir_path: "/mnt/production"
nfs_opts: "rw,hard,intr,rsize=8192,wsize=8192"
nfs_fstype: "nfs4"
local_dir_owner: "www-data"
local_dir_group: "www-data"
local_dir_mode: "0755"
before_service:
- "nginx.service"
- "php-fpm.service"
# backup share
- nfs_host: "nfs.example.com"
nfs_dir: "/exports/backups"
local_dir_path: "/mnt/backups"
nfs_opts: "ro,soft,timeo=30"
Usage
This repository has no playbook.yaml. The role (nfs_client) is consumed as a role by other playbooks.
Operational notes
- Installs
nfs-common. - For every entry the role creates the local directory, writes
/etc/systemd/system/<unit>.mount, reloads systemd, starts and enables the unit, and then re-applies the directory ownership and mode (the mounted share may have changed them). - The unit name is derived from
local_dir_path(for example/mnt/productionbecomesmnt-production.mount; dashes in the path are escaped as\x2d). - Each unit is ordered after
network-online.targetandremote-fs.target, and before anybefore_serviceentries.