---

- name: yum install dependencies
  yum:  name=perl,pciutils,gtk2,atk,cairo,gcc-gfortran,libxml2-python,tcsh,libnl,lsof,tcl,tk
  sudo: true
  ignore_errors: true
  
- name: yum update to upgrade kernel
  shell: "yum update -y"
  sudo: true
  when: ansible_os_family=="RedHat" and ansible_distribution_major_version == "7"
  
#
# A REBOOT IS NEEDED AFTER a KERNEL UPDATE
#
- name: restart machine
  shell: sleep 5; sudo shutdown -r now "Ansible updates triggered"
  async: 2
  poll: 0
  ignore_errors: true
  sudo: true

- name: waiting for server to come back
  #local_action: wait_for host={{ ansible_host }} state=started port=22 delay=10 search_regex=OpenSSH
  local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=10 search_regex=OpenSSH
  sudo: false

- name: waiting for server to come back number 2
  local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=10 search_regex=OpenSSH
  sudo: false

- name: test for existing installation of drivers
  command: ibv_devinfo
  sudo: true
  register: drivers_installed
  ignore_errors: true

- name: copy driver source
  unarchive: copy=yes src=files/MLNX_OFED_LINUX-3.1-1.0.3-rhel7.1-x86_64-ext.tgz dest=/tmp
  sudo: true
  when: drivers_installed|failed and ansible_os_family=="RedHat" and ansible_distribution_major_version == "7"

- name: install drivers
  shell: ./mlnxofedinstall -q
  args:
    chdir: /tmp/MLNX_OFED_LINUX-3.1-1.0.3-rhel7.1-x86_64-ext
  sudo: true
  when: drivers_installed|failed and ansible_distribution_major_version == "7"

#
# A REBOOT IS NEEDED AFTER SUCCESSFUL INSTALL
#
- name: restart machine
  command: sleep 5; sudo shutdown -r now "Ansible updates triggered"
  async: 2
  poll: 0
  ignore_errors: true
  sudo: true

- name: waiting for server to come back
  local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=10 search_regex=OpenSSH
  sudo: false

- name: waiting for server to come back 2
  local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=10 search_regex=OpenSSH
  sudo: false

- name: get IP address
  local_action: command ./scripts/map_ib_ip.pl {{ inventory_hostname }}
  register: ip_address
  
- name: template IP address
  template: dest=/etc/sysconfig/network-scripts/ifcfg-ens6 src=ifcfg-ens6.j2 owner=root group=root
  sudo: true
  when: ansible_distribution_major_version == "7"
 
- name: bring up interface
  command: ifup ens6
  sudo: true
  when: ansible_distribution_major_version == "7"