--- # 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