---
# collectd server setup

# install pkg
- name: install collectd server packages (rhel 7)
  package: name={{ item }} state=present
  with_items:
  - collectd-rrdtool
  - collectd-web
  - collectd-rabbitmq-data
  notify:
  - restart collectd
  tags:
  - config
  - collectd/server
  when: ansible_distribution_major_version|int == 7

- name: install collectd server packages (rhel 8)
  package: name={{ item }} state=present
  with_items:
  - collectd-rrdtool
  - collectd-web
  - collectd-rabbitmq-data
  - collectd-ipa-data
  notify:
  - restart collectd
  tags:
  - config
  - collectd/server
  when: ansible_distribution_major_version|int == 8

# install collectd types
- name: install collectd types
  copy:
    src: "{{ item }}"
    dest: /usr/share/collectd/{{ item }}
  loop:
  - fmn-types.db
  notify:
  - restart collectd
  tags:
  - config
  - collectd/server

# install collectd configs
- name: install collectd config
  copy:
    src: "{{ item }}"
    dest: /etc/collectd.d/{{ item }}
  loop:
  - rrdtool.conf
  - fmn.conf
  - unixsock.conf
  notify:
  - restart collectd
  tags:
  - config
  - collectd/server

# install apache config
- name: install collectd apache config
  copy: src=collectd.conf dest=/etc/httpd/conf.d/collectd.conf
  tags:
  - config
  - collectd/server

# install upgrade target
- name: install collect upgrade target to handle v4 clients
  copy: src=vfive-upgrade.conf dest=/etc/collectd.d/vfive-upgrade.conf
  tags:
  - config
  - collectd/server

# create /var/log/collectd as it's on a larger volume
- name: create /var/log/collectd
  file: path=/var/log/collectd owner=root group=root mode=0755 state=directory
  tags:
  - config
  - collectd/server

# push our custom config file for the graph CGIs
- name: push the collection.conf file
  copy:
    src: collection.conf
    dest: /etc/collection.conf
  tags:
  - config
  - collectd/server

- name: create the service configuration directory
  file:
    path: /etc/systemd/system/collectd.service.d
    state: directory
  tags:
  - config
  - collectd/server

- name: override the timeout for stopping collectd
  copy:
    src: service.timeout.conf
    dest: /etc/systemd/system/collectd.service.d/timeout.conf
  notify:
  - reload systemd
  tags:
  - config
  - collectd/server
