---
- name: Install dependencies
  apt:
    name: libxml-parser-perl
  tags: varnish

- include_role:
    name: evolix/remount-usr
  tags: varnish

- name: Create plugin directory
  file:
    name: /usr/local/share/munin/
    state: directory
    mode: "0755"
  tags: varnish

- name: Create plugin directory
  file:
    name: /usr/local/share/munin/plugins/
    state: directory
    mode: "0755"
  tags: varnish

- name: Copy varnish5 munin plugin
  copy:
    src: munin/varnish5_
    dest: /usr/local/share/munin/plugins/
    mode: "0755"
  notify: restart munin-node
  tags: varnish

- name: Enable varnish5 munin plugin
  file:
    src: /usr/local/share/munin/plugins/varnish5_
    dest: "/etc/munin/plugins/varnish5_{{item}}"
    state: link
  loop:
    - memory_usage
    - expunge
    - objects
    - request_rate
    - mgt_uptime
    - threads
    - backend_traffic
    - hit_rate
    - main_uptime
    - transfer_rates
    - bad
  notify: restart munin-node
  tags: varnish

- name: Copy varnish5 munin plugin config
  copy:
    src: munin/varnish5.conf
    dest: /etc/munin/plugin-conf.d/varnish5
    mode: "0644"
  notify: restart munin-node
  tags: varnish
