# - name: server | telegraf | remove repo
#   file:
#     path: "/etc/apt/sources.list.d/influxdata.list"
#     state: absent

- name: server | telegraf | download key
  uri:
    url: "https://repos.influxdata.com/influxdata-archive_compat.key"
    dest: "/tmp/influxdb.key"
    creates: "/tmp/influxdb.key"

- name: server | telegraf | verify and import key
  shell:
    cmd: "echo '393e8779c89ac8d958f81f942f9ad7fb82a25e133faddaf92e15b16e6ac9ce4c /tmp/influxdb.key' | sha256sum -c && cat /tmp/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg > /dev/null"
    creates: "/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg"

- name: server | telegraf | add repository
  shell:
    cmd: "echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive_compat.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list"
    creates: "/etc/apt/sources.list.d/influxdata.list"

- name: server | telegraf | install telegraf
  apt:
    name: "telegraf"
    state: latest
    update_cache: yes

- name: server | telegraf | copy basic config
  copy:
    dest: "/etc/telegraf/{{ item }}"
    src: "{{ item }}"
  loop:
    - telegraf.d/input_basics.conf
    - telegraf.d/output_influx.conf
  notify: restart_telegraf

  