---
- name: Install NFS server
  package: name=nfs-utils use=yum state=present

- name: configure NFS services
  file: src=etc-sysconfig-nfs dest=/etc/sysconfig/nfs owner=root group=root mode=0644

# figure if we need to reconfigure firewall if we run in a vApp
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Storage_Administration_Guide/nfs-serverconfig.html#s2-nfs-nfs-firewall-config

- name: Start rpcbind
  service: name=rpcbind state=started enabled=yes

- name: Start nfs
  service: name=nfs-server state=started enabled=yes

- name: Stop firewalld
  service: name=firewalld state=stopped enabled=no

- name: Stop iptables
  command: "iptables -F"
  ignore_errors: true

- name: Stop iptables
  command: "iptables-save"
  ignore_errors: true

- name: Create openshift volume group
  lvg: vg=openshift pvs=/dev/sdb

- name: Create lvm volumes
  lvol: vg=openshift lv=nfs size=95%FREE state=present shrink=no

- name: Create local partition on lvm lv
  filesystem:
    fstype: xfs
    dev: /dev/openshift/nfs

- name: Make mounts owned by nfsnobody
  file: path=/exports state=directory owner=nfsnobody group=nfsnobody mode=6775

- name: Mount the partition
  mount:
    name: /exports
    src: /dev/openshift/nfs
    fstype: xfs
    state: present

- name: Remount new partition
  command: "mount -a"

- name: Make mounts owned by nfsnobody
  file: path=/exports owner=nfsnobody group=nfsnobody mode=6775

- name: Make directory and set ownership
  file: path=/exports/registry state=directory owner=nfsnobody group=nfsnobody mode=0775

- name: Make directory and set ownership
  file: path=/exports/metrics state=directory owner=nfsnobody group=nfsnobody mode=0775

- name: Export the directories
  lineinfile:
    dest: "/etc/exports"
    line: "/exports *(rw,sync,all_squash)"
  notify: restart nfs

- name: Creates pv1 directory
  file: path="/pv1" state=directory owner=nfsnobody group=nfsnobody mode=0777

- name: Export the directories
  lineinfile:
    dest: "/etc/exports"
    line: "/pv1 *(rw,sync,all_squash)"
  notify: restart nfs

- name: Reload NFS exports
  command: exportfs -ra
