---

# Install autofs
- name: Installing AutoFS on {{ ansible_distribution }} {{ ansible_distribution_major_version }}
  apt:
    update_cache: yes
    state: present
    name:
      - autofs

# Create extra.autofs
- name: Creating AutoFS /etc/auto.master.d/extra.autofs
  template:
    src: extra.autofs.j2
    dest: /etc/auto.master.d/extra.autofs
    owner: root
    group: root
    mode: '0644'

# Create the dest directories
- name: Creating AutoFS destination directories
  file:
    path: "{{ item.dest }}"
    state: directory
    owner: "{{ superuser }}"
    group: "{{ supergroup }}"
    mode: '0755'
  loop: "{{ autofs_mounts }}"

# Create each servers /etc/auto.master.d/server.autofs file
- name: Creating AutoFS /etc/auto.master.d/server.autofs for each server in autofs_mounts
  template:
    src: mounts.autofs.j2
    dest: /etc/auto.master.d/mounts.autofs
    owner: root
    group: root
    mode: '0644'
  notify: reload-autofs
