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