# Set up and mount the data_cache as well as the old freenas
# TODO(jim/#infra) freenas shall be deprecated soon.

- block:
    - name: Install required packages for data_cache usage
      apt:
        name: nfs-common
        state: present
        update_cache: yes
        cache_valid_time: "{{ apt_cache_valid_time }}"
        install_recommends: no

    - name: Create mount for data_cache
      mount:
        state: mounted
        fstype: nfs
        src: "{{DATA_CACHE_HOST}}:{{DATA_CACHE_EXPORT}}"
        name: "{{DATA_CACHE_MOUNT_POINT}}"
        opts: "noatime,rsize=32768,wsize=32769,noresvport"
        passno: 0

    - name: Create mount for freenas
      mount:
        state: mounted
        fstype: nfs
        src: "{{FREENAS_LEGACY_HOST}}:{{FREENAS_LEGACY_EXPORT}}"
        name: "{{FREENAS_LEGACY_MOUNT_POINT}}"
        opts: "noatime,rsize=32768,wsize=32769,noresvport"
        passno: 0

    - name: Create mount for ceph logs
      mount:
        state: mounted
        fstype: ceph
        src: "{{CEPH_LOGS_HOST}}:{{CEPH_LOGS_EXPORT}}"
        name: "{{CEPH_LOGS_MOUNT_POINT}}"
        opts: "name=logs,secret={{ lookup('hashi_vault', 'secret=secret/ceph/logs').password }},_netdev"
        passno: 0

    - name: Create rw mount for ceph logs
      mount:
        state: mounted
        fstype: ceph
        src: "{{CEPH_LOGS_HOST}}:{{CEPH_LOGS_EXPORT}}"
        name: "{{CEPH_LOGS_RW_MOUNT_POINT}}"
        opts: "name=logs_rw,secret={{ lookup('hashi_vault', 'secret=secret/ceph/logs_rw').password }},_netdev"
        passno: 0

  become: yes
