---

- block:
  - name: get nvidia libs
    find:
      paths: "/usr/lib/x86_64-linux-gnu"
      patterns: "libnv*,libvdpau_nvidia*,libcuda.*"
      file_type: any
    register: nvidia_libs

  - name: create docker compose directory
    file:
      name: "/etc/docker-compose/collectors"
      state: directory

  - name: copy collectors service file
    template:
      src: "templates/docker-compose.template.yml"
      dest: "/etc/docker-compose/collectors/docker-compose.yml"
      owner: root
      group: root
      mode: u=rw,g=r,o=r
    notify: restart collectors

  - name: copy collectors upstart file
    copy:
      src: "files/zoox-pipedream-collectors.conf"
      dest: "/etc/init/zoox-pipedream-collectors.conf"
      owner: root
      group: root
      mode: u=rw,g=r,o=r
    notify: restart collectors
    when: ansible_distribution_version == '14.04'

  - name: install collectors service
    copy:
      src: "files/zoox-pipedream-collectors.service"
      dest: "/etc/systemd/system/zoox-pipedream-collectors.service"
      owner: root
      group: root
      mode: u=rwx,g=rx,o=rx
    notify: restart collectors
    when: ansible_distribution_version == '18.04'

  - name: run collectors
    service:
      name: zoox-pipedream-collectors
      state: started
      enabled: yes


  become: yes
