Files
Kamino/roles/nfs_client/tasks/validate.yml
T
Dragonish 5ce5e3c932
Build / build (pull_request) Successful in 31s
Molecule / molecule (pull_request) Failing after 43s
Lint / lint (pull_request) Successful in 1m53s
feat(nfs_client): add a role that manages NFS client entries in fstab
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
2026-11-27 21:47:09 +00:00

74 lines
3.5 KiB
YAML

---
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
# change. The argument spec (types, choices, required keys) runs before this file; the rules
# below are the ones between values. Each assert covers the whole list, not one item per loop
# pass, so the failure message is the assert's own. fstab fields are split on whitespace, so
# "one word" is tested with split rather than a pattern.
# The package and the fstab format are Debian's, and the role reads gathered facts.
- name: Require a Debian-family host
ansible.builtin.assert:
that:
- ansible_facts['os_family'] | default('') == 'Debian'
fail_msg: >-
nfs_client supports Debian-family hosts only (found: {{ ansible_facts['os_family'] | default('no gathered facts') }}).
The role reads gathered facts, so run it in a play that gathers them.
quiet: true
# Fact-computing tasks that the checks below read. A statement block in one template would leave
# whitespace around the result and make it a string instead of a list, so the list is built by
# appending one entry per pass.
- name: Start the resolved entries
ansible.builtin.set_fact:
__nfs_client_entries: []
# Defaults of the suboptions are applied here: the spec's suboption defaults are documentation.
- name: Resolve the entries
ansible.builtin.set_fact:
__nfs_client_entries: >-
{{ __nfs_client_entries + [{
'src': item.src | trim,
'path': item.path,
'opts': (item.opts | default('', true) | trim) or (nfs_client_default_opts | trim),
'state': item.state | default('present', true)
}] }}
loop: "{{ nfs_client_mounts }}"
loop_control:
label: "{{ item.path }}"
- name: Require a server and an export in every src
ansible.builtin.assert:
that:
- __nfs_client_entries | map(attribute='src') | map('split') | map('length') | reject('eq', 1) | list | length == 0
- __nfs_client_entries | map(attribute='src') | reject('search', '^[^ ]+:/') | list | length == 0
fail_msg: >-
nfs_client_mounts src must be one word of the form server:/export, without spaces
(offending: {{ __nfs_client_entries | map(attribute='src') | reject('search', '^[^ ]+:/') | list }}).
quiet: true
- name: Require an absolute mount point that is not the root
ansible.builtin.assert:
that:
- __nfs_client_entries | map(attribute='path') | map('split') | map('length') | reject('eq', 1) | list | length == 0
- __nfs_client_entries | map(attribute='path') | reject('search', '^/[^ ]*[^/ ]$') | list | length == 0
fail_msg: >-
nfs_client_mounts path must be an absolute path without spaces, not the root and without a trailing slash
(offending: {{ __nfs_client_entries | map(attribute='path') | reject('search', '^/[^ ]*[^/ ]$') | list }}).
quiet: true
- name: Require options that fit one fstab field
ansible.builtin.assert:
that:
- __nfs_client_entries | map(attribute='opts') | map('split') | map('length') | reject('eq', 1) | list | length == 0
fail_msg: >-
nfs_client_mounts options must be a non-empty comma-separated word without spaces, from the entry's opts or, when
that is empty, from nfs_client_default_opts.
quiet: true
- name: Require one entry per mount point
ansible.builtin.assert:
that:
- __nfs_client_entries | map(attribute='path') | unique | list | length == __nfs_client_entries | length
fail_msg: nfs_client_mounts lists the same path twice; each mount point may appear once.
quiet: true