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
49 lines
1.5 KiB
YAML
49 lines
1.5 KiB
YAML
---
|
|
# Validation first, under always, so a bad input fails before any change whatever tags the run
|
|
# selects.
|
|
- name: Validate the role inputs
|
|
ansible.builtin.import_tasks: validate.yml
|
|
tags: always
|
|
|
|
- name: Install the NFS client package
|
|
become: true
|
|
ansible.builtin.apt:
|
|
name: "{{ __nfs_client_package }}"
|
|
state: present
|
|
update_cache: true
|
|
cache_valid_time: 3600
|
|
tags: [nfs_client, install]
|
|
|
|
# No owner, group or mode: once a share is mounted the path is the export root, and a chown or
|
|
# chmod there changes the permissions on the NFS server.
|
|
- name: Create the mount points # noqa: risky-file-permissions
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ item.path }}"
|
|
state: directory
|
|
loop: "{{ __nfs_client_entries | selectattr('state', 'eq', 'present') | list }}"
|
|
loop_control:
|
|
label: "{{ item.path }}"
|
|
tags: [nfs_client, configure]
|
|
|
|
# present writes the fstab line and mounts nothing. An absent entry only loses its line:
|
|
# ansible.posix.mount's own absent would also unmount the share and delete the mount point.
|
|
- name: Manage the fstab entries
|
|
become: true
|
|
ansible.posix.mount:
|
|
src: "{{ item.src }}"
|
|
path: "{{ item.path }}"
|
|
fstype: nfs
|
|
opts: "{{ item.opts }}"
|
|
dump: "0"
|
|
passno: "0"
|
|
state: "{{ 'present' if item.state == 'present' else 'absent_from_fstab' }}"
|
|
loop: "{{ __nfs_client_entries }}"
|
|
loop_control:
|
|
label: "{{ item.path }}"
|
|
notify: Reload systemd for the nfs_client fstab entries
|
|
tags: [nfs_client, configure]
|
|
|
|
- name: Flush handlers
|
|
ansible.builtin.meta: flush_handlers
|