---
- block:
  - name: Add required packages
    become: yes
    apt:
      name:
        - autoconf
        - libnl-route-3-200
        - graphviz
        - automake
        - dpatch
        - quilt
        - dkms
        - pkg-config
        - bison
        - autotools-dev
        - swig
        - tk
        - tcl
        - flex
        - chrpath
        - libltdl-dev
        - m4
        - debhelper
        - python-apt
        - lldpd
      state: present

  - name: Check if Mellanox driver is installed
    stat:
      path: /usr/bin/mst
    register: mlnx

  - name: Download MLNX_OFED driver tar
    get_url:
      dest: "/home/zoox/{{ weka_mlnx_driver_tar_name }}"
      url: "https://z3.zooxlabs.com/zoox-third-party/{{ weka_mlnx_driver_sha }}/{{ weka_mlnx_driver_tar_name }}"
    when: not mlnx.stat.exists

  - name: Extract MLNX_OFED driver tar
    unarchive:
      src: "/home/zoox/{{ weka_mlnx_driver_tar_name }}"
      dest: "/home/zoox/"
      remote_src: yes
    when: not mlnx.stat.exists

  - name: Delete MLNX_OFED driver tar
    file:
      path: "/home/zoox/{{ weka_mlnx_driver_tar_name }}"
      state: absent
    when: not mlnx.stat.exists

  - name: Install MLNX_OFED driver
    shell: "{{ weka_mlnx_driver_path }}/{{ weka_mlnx_setup_file }} -q --force"
    become: yes
    when: not mlnx.stat.exists

  - name: Delete MLNX_OFED driver extraction
    file:
      path: "{{ weka_mlnx_driver_path }}"
      state: absent
    when: not mlnx.stat.exists

  - name: reboot nodes
    reboot:
      post_reboot_delay: 30
      reboot_timeout: 600
    become: yes
    when: not mlnx.stat.exists

  tags: weka-common
