diff --git a/roles/helper/fstab/tasks/main.yml b/roles/helper/fstab/tasks/main.yml index 51fdf6d..5d47f8a 100644 --- a/roles/helper/fstab/tasks/main.yml +++ b/roles/helper/fstab/tasks/main.yml @@ -3,7 +3,7 @@ ansible.builtin.package: name: "{{ (_common + _specific[ansible_os_family]) | select }}" vars: - _common: [] + _common: [util-linux] _specific: Debian: - "{{ 'nfs-common' if ('nfs' in _fstypes) else None }}" @@ -21,6 +21,30 @@ retries: 12 delay: 5 +- name: Assert that fstab config matches existing filesystems + ansible.builtin.shell: + cmd: | + set -o errexit + FAILED=false + {% for v in _fstab %} + if TYPE="$(blkid -o value -s TYPE '{{ v.src }}')"; then + if [[ "$TYPE" != '{{ v.fstype | d('nfs') }}' ]]; then + echo "Filesystem type on device '{{ v.src }}' does not match requested fstab config ('$TYPE' != '{{ v.fstype | d('nfs') }}')." >&2 + echo 'Please consider fixing this problem manually before continuing.' >&2 + FAILED=true + fi + fi + {% endfor %} + if [[ "$FAILED" == true ]]; then + exit 1 + fi + executable: /bin/bash + when: _fstab | count > 0 + vars: + _fstab: >- + {{ fstab | d([]) | selectattr('src', 'defined') }} + changed_when: false + - name: Add to fstab and mount filesystems ansible.posix.mount: src: "{{ item.src }}"