---
- include_vars: mellanoxVars.yml

- name: yum install dependencies
  yum:  name=perl,pciutils,gtk2,atk,cairo,gcc-gfortran,libxml2-python,tcsh,libnl,lsof,tcl,tk,kernel-devel,python-devel,createrepo,rpm-build
  sudo: true
  ignore_errors: true
  when: ansible_os_family == "RedHat"
  
- name: test for existing installation of drivers
  command: ibv_devinfo
  sudo: true
  register: drivers_installed
  ignore_errors: true

- name: set install
  set_fact: install_now=True, reboot_now=False




- name: copy driver source
  #make this a variable
  unarchive: copy=no src="http://consistency0/src/{{ MELLANOX_DRIVER_SRC }}.tgz" dest=/tmp 
  sudo: true
  #when: drivers_installed|failed and ansible_os_family=="RedHat" and ansible_distribution_major_version == "7"
  when: install_now

- name: install drivers
  shell: ./mlnxofedinstall -q --add-kernel-support --force
  args:
    #more changes
    chdir: "/tmp/{{ MELLANOX_DRIVER_SRC }}"
  sudo: true
  when: install_now



#
# A REBOOT IS NEEDED AFTER SUCCESSFUL INSTALL
#
- name: restart machine
  shell: "sleep 5; sudo shutdown -r now"
  async: 2
  poll: 1
  ignore_errors: true
  sudo: true
  when: reboot_now

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