---
# file: roles/netdata/tasks/install.yml

- name: "Clone NetData"
  git:
    accept_hostkey: true
    repo: "https://github.com/firehol/netdata.git"
    dest: "/opt/netdata"
    force: yes
  register: netdata_clone
  when: netdata_local_archive is not defined
  notify:
    - "Restart NetData"

- name: "Extract NetData Archive"
  unarchive:
    src: '/opt/{{ netdata_local_archive }}.zip'
    dest: '/opt'
    remote_src: yes
  register: netdata_extract
  when: netdata_local_archive is defined
  notify:
    - "Restart NetData"

- name: "Install and configure NetData"
  shell: ./netdata-installer.sh --dont-wait
  args:
    chdir: /opt/{{ netdata_local_archive|default('netdata') }}
  when: netdata_clone.changed or netdata_extract.changed