feat(nfs_client): add a role that manages NFS client entries in fstab #451

Open
Dragonish wants to merge 2 commits from feat/402-nfs-client into main
pull from: feat/402-nfs-client
Collaborator

What and why

Adds the nfs_client role proposed in #402: it installs nfs-common and manages NFS mount entries in /etc/fstab. It never mounts or unmounts anything.

Refs #402

  • Inputs: nfs_client_mounts (a list of src, path, optional opts, state present or absent) and nfs_client_default_opts (default _netdev,nofail; x-systemd.automount is left to the host that wants it).
  • 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.
  • fstab only: present writes the line, absent maps to ansible.posix.mount's absent_from_fstab, which removes the line and leaves the share and the directory alone. The module's own absent would also unmount and delete the mount point. A handler reloads systemd after a change.
  • No new dependency: ansible.posix >=2.2.0 is already in galaxy.yml; the pull request only names nfs_client in the comment above it.
  • Platforms: Ubuntu noble and resolute, the platforms the scenario runs on. Debian trixie is listed under "Untested platforms" in the README until the Debian image (#226) exists.
  • Changelog fragment 402-nfs-client.yml (minor_changes); the role is added to the role lists in README.md and galaxy.yml. It is not on the Roadmap list.

Verified

  • yamllint and ansible-lint (profile production) pass on roles/nfs_client; all commit-stage hooks passed; ansible-test sanity passed in the pre-push hook; ansible-playbook --syntax-check passes for the scenario's converge.yml, prepare.yml and verify.yml.
  • The role's validation, run on a controller against localhost with Ansible's own engine, for 17 inputs: the entries come out as a list, defaults and an empty opts fall back correctly, and every refusal carries its own message. This found three defects before the push: the resolved entries were a string, a looped assert hid its message, and an IPv6 server was rejected.
  • The controller-side refusals of verify.yml (14 cases, run once on localhost in check mode, as in the other roles) each matched their expected message when run against localhost: 14 rescued, 0 failed.
  • ansible.posix.mount behaviour against a scratch fstab with the same parameters as the role: a seeded line for the same path with another server is replaced once, an absent entry loses its line only (its directory and the file in it stay), and a second pass reports changed=False for every task.
  • An independent read-only review of the role against roles/AGENTS.md; its findings are fixed in this branch.
  • Molecule, run 6331 on head fcd2290 (run): the whole sequence passed on noble and resolute: syntax, create, prepare, check on a fresh host, converge, check on the configured host, idempotence and verify. That covers the nfs-common install, the fstab fields, the unchanged owner and mode of an existing mount point, nothing mounted, and the daemon-reload handler: systemd has a mount unit for each new entry and none for the removed one. Lint and Build passed too.
  • The first Molecule run failed in the fresh-host check, because the image ships without apt lists and --check does not refresh them (No package matching 'nfs-common' is available). fcd2290 refreshes the cache in prepare.yml, as the docker, pihole, system_baseline and traefik scenarios do.

Not verified

  • A real share: the server in the scenario does not exist, so nothing is ever mounted. Options other than the defaults and x-systemd.automount were not tried. Debian trixie is untested.
  • The permission note for a mounted share whose server is gone is reasoned, not tested.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Adds the `nfs_client` role proposed in #402: it installs `nfs-common` and manages NFS mount entries in `/etc/fstab`. It never mounts or unmounts anything. Refs #402 - **Inputs:** `nfs_client_mounts` (a list of `src`, `path`, optional `opts`, `state` `present` or `absent`) and `nfs_client_default_opts` (default `_netdev,nofail`; `x-systemd.automount` is left to the host that wants it). - **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. - **fstab only:** `present` writes the line, `absent` maps to `ansible.posix.mount`'s `absent_from_fstab`, which removes the line and leaves the share and the directory alone. The module's own `absent` would also unmount and delete the mount point. A handler reloads systemd after a change. - **No new dependency:** `ansible.posix >=2.2.0` is already in `galaxy.yml`; the pull request only names `nfs_client` in the comment above it. - **Platforms:** Ubuntu noble and resolute, the platforms the scenario runs on. Debian trixie is listed under "Untested platforms" in the README until the Debian image (#226) exists. - Changelog fragment `402-nfs-client.yml` (`minor_changes`); the role is added to the role lists in `README.md` and `galaxy.yml`. It is not on the Roadmap list. ## Verified - `yamllint` and `ansible-lint` (profile `production`) pass on `roles/nfs_client`; all commit-stage hooks passed; `ansible-test sanity` passed in the pre-push hook; `ansible-playbook --syntax-check` passes for the scenario's `converge.yml`, `prepare.yml` and `verify.yml`. - The role's validation, run on a controller against localhost with Ansible's own engine, for 17 inputs: the entries come out as a list, defaults and an empty `opts` fall back correctly, and every refusal carries its own message. This found three defects before the push: the resolved entries were a string, a looped `assert` hid its message, and an IPv6 server was rejected. - The controller-side refusals of `verify.yml` (14 cases, run once on localhost in check mode, as in the other roles) each matched their expected message when run against localhost: 14 rescued, 0 failed. - `ansible.posix.mount` behaviour against a scratch fstab with the same parameters as the role: a seeded line for the same path with another server is replaced once, an `absent` entry loses its line only (its directory and the file in it stay), and a second pass reports `changed=False` for every task. - An independent read-only review of the role against `roles/AGENTS.md`; its findings are fixed in this branch. - **Molecule, run 6331 on head `fcd2290` ([run](https://git.rkdr.net/Mortis/Kamino/actions/runs/6331)):** the whole sequence passed on noble and resolute: syntax, create, prepare, check on a fresh host, converge, check on the configured host, idempotence and verify. That covers the `nfs-common` install, the fstab fields, the unchanged owner and mode of an existing mount point, nothing mounted, and the `daemon-reload` handler: systemd has a mount unit for each new entry and none for the removed one. Lint and Build passed too. - The first Molecule run failed in the fresh-host check, because the image ships without apt lists and `--check` does not refresh them (`No package matching 'nfs-common' is available`). `fcd2290` refreshes the cache in `prepare.yml`, as the docker, pihole, system_baseline and traefik scenarios do. ## Not verified - A real share: the server in the scenario does not exist, so nothing is ever mounted. Options other than the defaults and `x-systemd.automount` were not tried. Debian trixie is untested. - The permission note for a mounted share whose server is gone is reasoned, not tested. --- - [ ] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Dragonish added 1 commit 2026-11-27 21:50:46 +00:00
feat(nfs_client): add a role that manages NFS client entries in fstab
Build / build (pull_request) Successful in 31s
Molecule / molecule (pull_request) Failing after 43s
Lint / lint (pull_request) Successful in 1m53s
5ce5e3c932
Installs nfs-common and manages NFS mount entries from nfs_client_mounts
(src, path, optional opts, state present or absent). Each mount point is
created without owner, group or mode, because once a share is mounted a
chown or chmod there changes the permissions on the NFS server. The role
writes only the fstab line and reloads systemd; it never mounts or
unmounts. An absent entry maps to ansible.posix.mount's absent_from_fstab,
which removes the line and leaves the share and the directory alone.

The default options are _netdev,nofail. x-systemd.automount is left out.

Verified locally: yamllint, ansible-lint (production profile), syntax check
of the scenario playbooks, the controller-side refusals of verify.yml (14
cases, each matched on its own message), and the module's fstab behaviour
against a scratch fstab (replacement, absent_from_fstab, idempotence).
Not verified: Molecule, which runs only in CI; the apt install and the
daemon-reload handler; that systemd generates the mount units in the
scenario's containers.

Refs #402

Assisted-by: Claude Code
CODEOWNERS rules requested review from Defame1297 2026-11-27 21:50:46 +00:00
Owner

Molecule fails on the first check step on both platforms: No package matching 'nfs-common' is available. Check mode doesn't refresh the apt cache, and the test images ship without package lists, so the install task can't see the package.

The other roles that install packages refresh the cache in prepare.yml (see roles/docker/molecule/default/prepare.yml). Adding this as the first task of roles/nfs_client/molecule/default/prepare.yml should fix it:

    # check runs before converge, so the cache must already list the packages the role installs.
    - name: Refresh the apt cache
      ansible.builtin.apt:
        update_cache: true

Assisted-by: Claude Code

Molecule fails on the first `check` step on both platforms: `No package matching 'nfs-common' is available`. Check mode doesn't refresh the apt cache, and the test images ship without package lists, so the install task can't see the package. The other roles that install packages refresh the cache in `prepare.yml` (see `roles/docker/molecule/default/prepare.yml`). Adding this as the first task of `roles/nfs_client/molecule/default/prepare.yml` should fix it: ```yaml # check runs before converge, so the cache must already list the packages the role installs. - name: Refresh the apt cache ansible.builtin.apt: update_cache: true ``` Assisted-by: Claude Code
Dragonish added 1 commit 2026-11-27 22:01:44 +00:00
test(nfs_client): refresh the apt cache in the scenario's prepare
Build / build (pull_request) Successful in 31s
Molecule / molecule (pull_request) Successful in 2m5s
Lint / lint (pull_request) Successful in 2m47s
fcd2290e14
The molecule image ships without apt lists, and --check does not refresh
them, so the fresh-host check found no nfs-common to install and failed
with "No package matching 'nfs-common' is available". The docker, pihole,
system_baseline and traefik scenarios refresh the cache in prepare for the
same reason.

Refs #402

Assisted-by: Claude Code
Dragonish scheduled this pull request to auto merge when all checks succeed 2026-11-27 22:06:13 +00:00
All checks were successful
Build / build (pull_request) Successful in 31s
Required
Details
Molecule / molecule (pull_request) Successful in 2m5s
Required
Details
Lint / lint (pull_request) Successful in 2m47s
Required
Details
This pull request has official review requests.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/402-nfs-client:feat/402-nfs-client
git checkout feat/402-nfs-client
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#451