03_controller_mount.ymlΒΆ

---
- name: "πŸ” Detect controller {{ DIR_VAR_LIB }} pre-mount state"
  ansible.builtin.script:
    cmd: "{{ lookup('path_absolute', 'roles/svc-storage-nfs-client/files/shell/premount_state.sh') }}"
    executable: /bin/bash
  environment:
    DIR_VAR_LIB: "{{ DIR_VAR_LIB }}"
  register: _ctrl_premount_state
  changed_when: false

- name: "βœ… Assert controller {{ DIR_VAR_LIB }} has no pre-existing data (mount hides it)"
  ansible.builtin.assert:
    that:
      - >-
        'STATE=mounted' in _ctrl_premount_state.stdout
        or 'STATE=empty' in _ctrl_premount_state.stdout
    fail_msg: >-
      Pre-existing local data found at controller {{ DIR_VAR_LIB }}; NFS
      mount-over would silently hide it. Migrate or remove the local tree
      on the controller, then re-run the deploy. Probe said:
      {{ _ctrl_premount_state.stdout | trim }}

- name: "βœ… Ensure controller mount point exists"
  ansible.builtin.file:
    path: "{{ DIR_VAR_LIB }}"
    state: directory

- name: "πŸ“¦ Install the NFS client"
  package_install: # nocheck: package-install runs on the controller by delegation, outside any host's batch
    id: nfs-client

- name: "πŸ”Ž Read current mount source at controller {{ DIR_VAR_LIB }}"
  ansible.builtin.command:
    cmd: "findmnt -n -o SOURCE {{ DIR_VAR_LIB }}"
  register: _ctrl_mount_src
  changed_when: false
  failed_when: false

- name: "πŸ”Œ Unmount foreign source so the ephemeral (re)mount is not refused"
  ansible.posix.mount:
    path: "{{ DIR_VAR_LIB }}"
    state: unmounted
  when:
    - "'STATE=mounted' in _ctrl_premount_state.stdout"
    - (_ctrl_mount_src.stdout | trim) | length > 0
    - (_ctrl_mount_src.stdout | trim) != STORAGE_NFS_CONTROLLER_SRC

- name: "πŸ”— Mount cluster-shared infinito state on controller"
  ansible.posix.mount:
    path: "{{ DIR_VAR_LIB }}"
    src: "{{ STORAGE_NFS_CONTROLLER_SRC }}"
    fstype: "{{ STORAGE_NFS_FSTYPE }}"
    opts: "{{ STORAGE_NFS_MOUNT_OPTS }}"
    state: ephemeral
  register: _ctrl_nfs_mount
  retries: 12
  delay: 5
  until: _ctrl_nfs_mount is succeeded

- name: "πŸ”§ Align the controller's directory delegations with the ganesha server"
  ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/svc-storage-nfs-client/tasks/directory_delegations.yml') }}"
  when: lookup('nfs_flavor') == 'ganesha'