---

- ansible.builtin.include_role:
    name: remount-usr

- name: Create local munin directory
  ansible.builtin.file:
    name: /usr/local/share/munin/
    state: directory
    mode: "0755"

- name: Create plugin directory
  ansible.builtin.file:
    name: /usr/local/share/munin/plugins/
    state: directory
    mode: "0755"

- name: Get Munin plugins
  ansible.builtin.get_url:
    url: "https://raw.githubusercontent.com/munin-monitoring/contrib/master/plugins/libvirt/{{ item }}"
    dest: "/usr/local/share/munin/plugins/"
    mode: "0755"
    force: false
  loop:
    - kvm_cpu
    - kvm_io
    - kvm_mem
  notify: restart munin-node

- name: Enable Munin plugins
  ansible.builtin.file:
    src: "/usr/local/share/munin/plugins/{{ plugin_name }}"
    dest: "/etc/munin/plugins/{{ plugin_name }}"
    state: link
    force: true
  loop:
    - kvm_cpu
    - kvm_io
    - kvm_mem
  loop_control:
    loop_var: plugin_name
  notify: restart munin-node

- name: Copy Munin plugins conf
  ansible.builtin.copy:
    src: files/munin-plugins
    dest: "/etc/munin/plugin-conf.d/kvm"
    mode: "0644"
  notify: restart munin-node
