---

- name: ensure nfs client utils are installed
  apt:
    name:
      - nfs-common
    state: present
  tags:
    - nfs-client

- name: ensure cifs client utils are installed
  apt:
    name:
      - cifs-utils
      - smbclient
    state: present
  when: nfs_enable_cifs
  tags:
    - nfs-client

- name: ensure quota tools are installed
  apt:
    name: quota
    state: present
  when: nfs_enable_quota
  tags:
    - nfs-client

- name: ensure the nfs-client service is configured for nfs4
  copy:
    src: nfs-common
    dest: /etc/default/nfs-common
    owner: root
    group: root
    mode: '0644'
  notify:
    - restart nfs-client
  tags:
    - nfs-client

- name: ensure nfs module is loaded
  modprobe:
    name: nfs
    state: present
    params: nfs4_disable_idmapping=N
    persistent: present
  tags:
    - nfs-client

- name: Disable rpc-svcgssd
  systemd:
    name: rpc-svcgssd.service
    masked: true
  tags:
    - nfs-client

- name: ensure nfs-common is enabled
  service:
    name: nfs-client.target
    state: started
    enabled: true
  tags:
    - nfs-client

- name: Disable and stop autofs
  systemd:
    name: autofs
    state: stopped
    enabled: false
  ignore_errors: true
  tags:
    - nfs-client

- name: Remove old autofs directory
  file:
    path: /net
    state: absent
  tags:
    - nfs-client

- name: Ensure /home is a directory
  file:
    path: /home
    state: directory
    owner: root
    group: root
    mode: '0755'
  tags:
    - nfs-client

- name: Ensure mountpoints are directories
  file:
    path: "{{ item.dest }}"
    state: directory
  loop: "{{ nfs_shares }}"
  tags:
    - nfs-client

- name: Create fstab entries
  mount:
    fstype: "nfs"
    src: "{{ item.src }}"
    path: "{{ item.dest }}"
    opts: "{{ item.options }}{{ maybe_automount }}"
    state: mounted
  loop: "{{ nfs_shares }}"
  vars:
    maybe_automount: >-
      {% if automount -%}
      ,x-systemd.automount
      {%- endif %}
  tags:
    - nfs-client

- name: configure default umask and other user related stuff
  copy:
    src: login.defs
    dest: /etc/login.defs
    owner: root
    group: root
    mode: '0644'
  tags:
    - nfs-client
    - umask
