# nfs_client Installs the NFS client (`nfs-common`) and manages NFS mount entries in `/etc/fstab`. It writes the fstab line, creates the mount point and reloads systemd; it never mounts or unmounts anything. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth. ## Supported platforms Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role asserts a Debian-family host before any change. Untested platforms: Debian 13 (trixie). The role has no OS-specific branch, but no scenario runs on it until the Debian image (#226) exists. ## Requirements and run order - Use it by its fully qualified name, `mortis.kamino.nfs_client`, in a play that gathers facts: the Debian-family assert reads them. - Role dependencies: none. The role calls `ansible.posix.mount`, so the Collection's `ansible.posix` dependency applies. - `become` is used for every task that changes the host. - The role does not set up an NFS server, autofs, CIFS/SMB or Kerberos, and it does not wait for a mount. ## Role variables | Variable | Default | Description | |---|---|---| | `nfs_client_mounts` | `[]` | The mounts to manage: a list of entries, each mount point once. With no entries only the client package is installed. | | `nfs_client_default_opts` | `_netdev,nofail` | Options for an entry that sets none. | An entry takes these keys: | Key | Default | Description | |---|---|---| | `src` | required | The export as `server:/export`, one word without spaces. | | `path` | required | The mount point: absolute, without spaces, not `/`, no trailing slash. | | `opts` | `nfs_client_default_opts` | The fstab options, one comma-separated word. Put the NFS version here, for example `vers=4.2`. | | `state` | `present` | `present` writes the fstab line. `absent` removes it and nothing else. | ## Tags - `nfs_client`: everything the role does. - `install`: the client package. - `configure`: the mount points and the fstab entries. Validation runs under `always`, so a bad input fails before any change whatever tags the run selects. ## Example play ```yaml - name: NFS client hosts: nfs_clients roles: - role: mortis.kamino.nfs_client vars: nfs_client_mounts: - src: nas.example:/export/data path: /mnt/data - src: nas.example:/export/media path: /mnt/media opts: _netdev,nofail,ro,vers=4.2 ``` ## Tests `molecule/default` runs on Ubuntu noble and resolute: a check on a fresh host, the converge, a check on the configured host, an idempotence run, and `verify.yml`. The scenario seeds an fstab line for `/mnt/data` that names another server and a line and a directory for `/mnt/old`, so the run shows that a line is replaced once and that an `absent` entry loses only its line. `verify.yml` first checks a refusal for each validation on the controller, once, in check mode (a missing or empty `src`, a `src` without an export, a relative path, the root, a trailing slash, options with a space or none, a duplicate path, `mounted` and `remounted`, a host without facts). It then asserts, on each container, the client package, the exact fstab fields, that a new mount point is root's and an existing one keeps its owner and mode, that the removed entry's directory and file are intact, that `/proc/mounts` shows nothing mounted, and that systemd has a mount unit for each new entry and none for the removed one. What it does not show: that a real share mounts at boot (the server in the scenario does not exist), that `x-systemd.automount` or any option other than the defaults behaves, and Debian trixie. ## Notes - **Why only the fstab.** `ansible.posix.mount` with `state: mounted` mounts from the play's own process. Where that process runs in a private mount namespace (a hardened sshd unit can), systemd and containers do not see the mount. The role writes the line and reloads systemd, and the share is mounted at the next boot or with `systemctl start .mount`. New options reach a share that is already mounted only after it is remounted or the host reboots. - **No owner, group or mode on the mount point.** Once a share is mounted the path is the export root, and a `chown` or `chmod` there changes the permissions on the NFS server. A new directory gets the system defaults, and an existing one is left as it is. - **A share that is mounted and unreachable.** On a re-run the role looks at each `present` mount point, and a mounted path whose server is gone can block that look. Fix or unmount the share, or leave that entry out of the run, before running the role again. - **`absent` leaves the share alone.** The entry's line is removed; the share stays mounted until it is unmounted and the mount point is not deleted. - **Default options.** `_netdev` orders the mount after the network and puts it in `remote-fs.target`; `nofail` keeps an unreachable server from holding up the boot. `x-systemd.automount` changes when a mount appears and can hide an unreachable server until first access, so it is left to the host that wants it. The `docker` role's `docker_stop_at_shutdown` relies on the same `remote-fs.target` ordering. - `--check` is the supported preview; a play-level `check_mode: true` is not supported. `apt` and the fstab edit both report what would change. - Idempotent: yes.