---

- name: install python-retask
  yum: name=python-retask state=present
  tags:
  - collectd

- name: Copy in /usr/local/bin/fcomm-queue-collectd
  copy: >
    src=fcomm-queue-collectd.py
    dest=/usr/local/bin/fcomm-queue-collectd
    mode=0755
  tags:
  - collectd
  notify: restart collectd

- name: Copy in /etc/collectd.d/fcomm-queue.conf
  copy: >
    src=fcomm-queue.conf
    dest=/etc/collectd.d/fcomm-queue-conf
  tags:
  - collectd
  notify: restart collectd

# Three tasks for handling our custom selinux module.
- name: ensure a directory exists for our custom selinux module
  file: dest=/usr/share/collectd state=directory
  tags:
  - collectd
  - selinux

- name: copy over our fcomm collectd selinux module
  copy: src=selinux/fi-collectd-fcomm.pp dest=/usr/share/collectd/fi-collectd-fcomm.pp
  register: ficfcomm_module
  tags:
  - collectd
  - selinux

- name: check to see if its even installed yet
  shell: semodule -l | grep fi-collectd-fcomm | wc -l
  register: ficfcomm_grep
  always_run: True
  changed_when: "'0' in ficfcomm_grep.stdout"
  tags:
  - collectd
  - selinux

- debug: var=ficfcomm_grep
  tags:
  - collectd
  - selinux

- debug: msg="{{ficfcomm_grep|changed}}"
  tags:
  - collectd
  - selinux

- name: install our fcomm collectd selinux module
  command: semodule -i /usr/share/collectd/fi-collectd-fcomm.pp
  when: ficfcomm_module|changed or ficfcomm_grep|changed
  tags:
  - collectd
  - selinux

- name: lastly, set some selinux booleans
  seboolean: name={{item}} persistent=yes state=yes
  with_items:
  - collectd_tcp_network_connect
  tags:
  - collectd
  - selinux
