---
# tasks to install prometheus gluster_exporter
# https://github.com/ofesseler/gluster_exporter

# install packages
- name: Update apt cache.
  apt: update_cache=yes cache_valid_time=86400

- name: Install gluster_exporter dependencies.
  apt: "name={{ item }} state=installed"
  with_items:
    - golang-go

- name: make golang workspace
  file:
    path: /opt/golang
    state: directory
    mode: 0775

- name: install gluster_exporter
  shell: GOPATH=/opt/golang go get github.com/ofesseler/gluster_exporter

- name: add gluster_exporter to startup
  lineinfile:
    dest: /etc/rc.local
    regexp: '/opt/golang/bin/gluster_exporter'
    line: 'nohup /opt/golang/bin/gluster_exporter --profile &'
    insertbefore: "^exit 0"

- name: start gluster_exporter
  shell: nohup /opt/golang/bin/gluster_exporter --profile &
