---

- name: add kubernetes repo
  copy: src=kubernetes.repo dest=/etc/yum.repos.d/ owner=root group=root mode=644
  tags: install

# add ElRepo GPG Key
- rpm_key:
    state: present
    key: https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
  tags: install

- name: add ElRepo (Nvidia kmod drivers)
  yum:
    name: http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
    state: present
  tags: install

- name: update sysctl to handle incorrectly routed traffic when iptables is bypassed
  copy: src=k8s.conf dest=/etc/sysctl.d/ owner=root group=root mode=644
  tags: install

- name: update sysctl
  command: /sbin/sysctl --system
  tags: install

- name: Install EPEL Repository
  yum: name=epel-release state=present
  tags: install

#likely need to add a reboot hook in here
#- name: update kernel and all other system packages
  #yum: name=* state=latest
  #tags: install

- name: disable swap
  command: /sbin/swapoff -a
  tags: install

# Disable selinux
- selinux:
    state: disabled
  tags: install

- name: install common packages
  yum: 
    name:
      - gcc
      - nfs-utils
      - python-pip
      - docker
      - bash-completion
      - kubelet
      - kubeadm
      - kubectl
      - nvidia-detect
    state: present
  tags: install

- name: install InfiniBand Support
  yum:
    name: "@Infiniband Support"
    state: present

- name: Install KSonnet
  unarchive:
    src: https://github.com/ksonnet/ksonnet/releases/download/v0.13.1/ks_0.13.1_linux_amd64.tar.gz
    dest: /usr/bin/
    extra_opts: [--strip-components=1]
    remote_src: yes
    exclude:
      - ks_0.11.0_linux_amd64/CHANGELOG.md
      - ks_0.11.0_linux_amd64/CODE-OF-CONDUCT.md
      - ks_0.11.0_linux_amd64/CONTRIBUTING.md
      - ks_0.11.0_linux_amd64/LICENSE
      - ks_0.11.0_linux_amd64/README.md
  tags: install

- name: upgrade pip
  command: /bin/pip install --upgrade pip
  tags: install

#- name: Enable DevicePlugins for all GPU nodes (nvidia-container-runtime-hook)
  #copy: src=nvidia dest=/usr/libexec/oci/hooks.d/ owner=root group=root mode=755
  #tags: install

- name: Add KUBE_EXTRA_ARGS to enable GPUs
  lineinfile:
    path: /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
    line: 'Environment="KUBELET_EXTRA_ARGS=--feature-gates=DevicePlugins=true"'
    insertbefore: 'KUBELET_KUBECONFIG_ARGS='
  tags: install

- name: Start and Enable docker service
  service:
    name: docker
    state: restarted
    enabled: yes
  tags: install

- name: Start and Enable Kubernetes - kubelet
  service:
    name: kubelet
    state: restarted
    enabled: yes
  tags: install

- name: Start and rpcbind service
  service:
    name: rpcbind
    state: restarted
    enabled: yes
  tags: install

- name: Start and nfs-server service
  service:
    name: nfs-server
    state: restarted
    enabled: yes
  tags: install

- name: Start and nfs-lock service
  service:
    name: nfs-lock
    state: restarted
    enabled: yes
  tags: install

- name: Start and nfs-idmap service
  service:
    name: nfs-idmap
    state: restarted
    enabled: yes
  tags: install
