- name: "Install 5 packages: munin, munin-node, munin-plugins-extra, libcgi-fast-perl, libapache2-mod-fcgid (debuntu)"
  package:
    name:
      - munin
      - munin-node
      - munin-plugins-extra
      - libcgi-fast-perl
      - libapache2-mod-fcgid
    state: present
  when: is_debuntu

- name: "Install 2 packages: munin, munin-node (OS's other than debuntu)"
  package:
    name:
      - munin
      - munin-node
    state: present
  when: not is_debuntu

- name: 'Install from template: /etc/munin/munin.conf'
  template:
    src: munin.conf.j2
    dest: /etc/munin/munin.conf

- name: 'Install from template: /etc/{{ apache_conf_dir }}/munin24.conf'
  template:
    src: munin24.conf.j2
    dest: "/etc/{{ apache_conf_dir }}/munin24.conf"    # apache2/sites-available
  when: apache_installed is defined

- name: Establish username/password Admin/changeme in /etc/munin/munin-htpasswd
  htpasswd:
    path: /etc/munin/munin-htpasswd
    name: "{{ munin_username}}"    # Admin
    password: "{{ munin_password }}"    # changeme

- name: If MySQL is enabled, let Munin monitor it
  copy:
    src: "{{ item }}"
    dest: /etc/munin/plugins/
  with_items:
    - /usr/share/munin/plugins/mysql_
    - /usr/share/munin/plugins/mysql_bytes
    - /usr/share/munin/plugins/mysql_innodb
    - /usr/share/munin/plugins/mysql_isam_space_
    - /usr/share/munin/plugins/mysql_queries
    - /usr/share/munin/plugins/mysql_slowqueries
    - /usr/share/munin/plugins/mysql_threads
  when: mysql_enabled


# RECORD Munin AS INSTALLED

- name: "Set 'munin_installed: True'"
  set_fact:
    munin_installed: True

- name: "Add 'munin_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^munin_installed'
    line: 'munin_installed: True'
