- name: install network-scripts package
  package: name=network-scripts state=installed
  when: ansible_distribution_major_version|int >= 29 and ansible_distribution == 'Fedora'
  tags:
  - nfs/client

# Setup our idmapd.conf file. It should be loaded automagically.
- name: idmapd.conf
  copy: src=idmapd.conf dest=/etc/idmapd.conf
  tags:
  - nfs/client
  notify:
  - restart idmapd

# if we need to reload nm, we should do it now, not after roles.
- meta: flush_handlers

- name: check for netapp route
  command: ip route show
  register: netapproute
  check_mode: no
  changed_when: "1 != 1"
  tags:
  - nfs/client

- name: run netapp route if needed in rdu
  command: /usr/bin/nmcli c up eth1
  when: netapproute.stdout.find("172.31.1.0") == -1 and datacenter == 'rdu'
  tags:
  - nfs/client

#
# Install needed packages
#
- name: Install needed nfs packages
  package:
    name: "{{ item }}"
    state: present
  with_items:
  - nfs-utils
  - rpcbind
  tags:
  - nfs/client

- name: enable rpcbind services and run them (rhel 7+ and Fedora)
  service: name={{ item }}  enabled=true state=started
  with_items:
  - rpcbind
  when: ansible_distribution_major_version|int >= 7 and ansible_distribution == 'RedHat'
  tags:
  - nfs/client

- name: enable nfs-lock service and run them (rhel 7 and Fedora)
  service: name={{ item }}  enabled=true state=started
  with_items:
  - nfs-lock
  when: ansible_distribution_major_version|int == 7 and ansible_distribution == 'RedHat'
  tags:
  - nfs/client

- name: nfs mount points (iad2)
  mount: >
        name={{ mnt_dir }}
        src=ntap-iad2-c02-fedora01-nfs01a:/{{ nfs_src_dir }}
        fstype=nfs
        opts={{nfs_mount_opts}}
        passno=0
        dump=0
        state=mounted
  when: ( datacenter == 'iad2' or datacenter == 'staging' ) and (env != 'staging' or mount_stg is defined)
  tags:
  - nfs/client

- name: nfs mount points (rdu)
  mount: >
        name={{ mnt_dir }}
        src=172.31.1.11:/{{ nfs_src_dir }}
        fstype=nfs
        opts={{nfs_mount_opts}}
        passno=0
        dump=0
        state=mounted
  when: datacenter == 'rdu'
  tags:
  - nfs/client

#
# In stg we need to mount the koji01.stg volume rw and the
# production nfs volume ro. Since the setup here isn't good
# for multiple nfs mounts, we just hard code needed staging bits
# here. If it becomes more common to have multiple mounts, we
# should revisit how this role works.
#

- name: nfs mount points (stg) staging koji
  mount: >
        name=/mnt/fedora_koji
        src=10.3.167.64:/mnt/fedora_koji
        fstype=nfs4
        opts=rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=4
        passno=0
        dump=0
        state=mounted
  when: env == 'staging' and 'koji' in mnt_dir and '.s390.' not in inventory_hostname and not inventory_hostname.startswith('koji')
  tags:
  - nfs/client

- name: nfs mount points (stg) production koji ro
  mount: >
        name=/mnt/fedora_koji_prod
        src=ntap-iad2-c02-fedora01-nfs01a:/fedora_koji
        fstype=nfs
        opts=ro,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3
        passno=0
        dump=0
        state=mounted
  when: env == 'staging' and 'koji' in mnt_dir and '.s390.' not in inventory_hostname
  tags:
  - nfs/client
