---
- name: stat if etc systemd system roce_mode.service exists
  stat:
    path: /etc/systemd/system/roce_mode.service
  register: statrocemode

# todo handle multiple devices found
- name: query ibstat for devicename
  shell: /usr/sbin/ibstat | grep mlx5 | awk '{print $2}' | sed -r "s#'##g"
  register: qibdevicenames
  check_mode: no
  #when: not statrocemode.stat.exists

- name: print qibdevicenames
  debug:
    var: qibdevicenames

- name: template pfc-ecn script
  become: true
  template:
    src: pfc-ecn.sh.j2
    dest: /usr/sbin/pfc-ecn.sh
    owner: root
    group: root
    mode: u+rwx,g-wx,o-rwx

- name: template roce_mode.service file
  template: dest=/etc/systemd/system/roce_mode.service src=roce_mode.service.j2 owner=root group=root mode=0644
  become: true
  become_user: root
  register: service_file

- name: Reload systemd
  shell: systemctl daemon-reload
  become: true
  become_user: root
  when: service_file.changed
  register: reload_service

- name: enable roce_mode setting
  service: name=roce_mode state=started enabled=yes
  become: true
  when: service_file.changed

- name: enable roce_mode setting
  service: name=roce_mode state=started enabled=yes
  become: true
