- name: Install Telegraf from URL [RHEL/CentOS]
  yum:
    name: "{{ telegraf_install_rpm_url }}"
    state: present
  when: ansible_os_family == "RedHat"
  become: true
  become_user: root

- name: Download Telegraf package via URL [Debian/Ubuntu]
  get_url:
    url: "{{ telegraf_install_url }}"
    dest: /tmp/telegraf-ansible-download.deb
  when: ansible_os_family == "Debian"
  become: true
  become_user: root

- name: Install Telegraf package
  apt:
    deb: /tmp/telegraf-ansible-download.deb
    state: present
  when: ansible_os_family == "Debian"
  become: true
  become_user: root

- name: Make a directory for extra files
  file:
    state: directory
    mode: 'u=rwx,g=rx,o=rx'
    owner: 'telegraf'
    group: 'telegraf'
    path: '/opt/telegraf/bin'
  become: true
  become_user: root

- name: copy mountstats plugin
  copy:
    mode: 'u=rwx,g=rx,o=rx'
    src: telegraf_mountstats.py
    dest: '/opt/telegraf/bin/telegraf_mountstats.py'
  become: true
  become_user: root

- name: copy slurmstats plugin
  copy:
    mode: 'u=rwx,g=rx,o=rx'
    src: telegraf_slurmstats.py
    dest: '/opt/telegraf/bin/telegraf_slurmstats.py'
  become: true
  become_user: root

- name: Install Telegraf config
  template:
    src: telegraf.conf.j2
    dest: /etc/telegraf/telegraf.conf
    owner: telegraf
    group: telegraf
    mode: '640'
  notify:
    - "restart telegraf"
  become: true
  become_user: root


