---

- name: Assert
  assert:
    that: ansible_os_family in [ 'Debian', 'OpenBSD' ]

- name: apt install Collectd
  when: ansible_pkg_mgr == 'apt'
  apt:
    name: collectd
    install_recommends: no
    state: present
    update_cache: yes
    cache_valid_time: 3600

- name: pkg install Collectd
  when: ansible_pkg_mgr == 'openbsd_pkg'
  openbsd_pkg:
    name: '{{ openbsd_collectd_version[ansible_distribution_release] }}'
    state: present

- name: Create configuration directory
  file:
    path: /etc/collectd/collectd.conf.d/
    owner: root
    group: root
    mode: '0755'
    state: directory

- name: Base configuration
  copy:
    src: collectd.conf
    dest: /etc/collectd/collectd.conf
    owner: root
    group: root
    mode: '0644'
  notify:
  - Restart Collectd
