diff --git a/roles/munin/tasks/enable.yml b/roles/munin/tasks/enable.yml new file mode 100644 index 000000000..90f5dec4d --- /dev/null +++ b/roles/munin/tasks/enable.yml @@ -0,0 +1,67 @@ +- 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 | bool + +- name: Enable & Start munin-node systemd service + systemd: + name: munin-node + enabled: yes + state: started + when: munin_enabled | bool + +- name: Disable munin-node service if not munin_enabled + systemd: + name: munin-node + enabled: no + state: stopped + when: not munin_enabled + +- name: Create symlink munin24.conf from sites-enabled to sites-available (debuntu) + file: + src: /etc/apache2/sites-available/munin24.conf + path: /etc/apache2/sites-enabled/munin24.conf + state: link + when: munin_enabled and not nginx_enabled + +- name: Remove symlink /etc/apache2/sites-enabled/munin24.conf if not munin_enabled (debuntu) + file: + path: /etc/apache2/sites-enabled/munin24.conf + state: absent + when: not munin_enabled or nginx_enabled + +- name: Install /etc/nginx/conf.d/munin24-nginx.conf, from templates + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: 0644 + with_items: + - { src: 'munin24-nginx.conf.j2', dest: '/etc/nginx/conf.d/munin24-nginx.conf + when: munin_enabled | bool and nginx_enabled | bool + +- name: Add 'munin' variable values to {{ iiab_ini_file }} + ini_file: + path: "{{ iiab_ini_file }}" + section: munin + option: "{{ item.option }}" + value: "{{ item.value }}" + with_items: + - option: name + value: Munin + - option: description + value: '"Munin is a networked resource monitoring tool that can help analyze resource trends and \"what just happened to kill our performance?\" problems."' + - option: installed + value: "{{ munin_install }}" + - option: enabled + value: "{{ munin_enabled }}" diff --git a/roles/munin/tasks/install.yml b/roles/munin/tasks/install.yml new file mode 100644 index 000000000..19f8b8de2 --- /dev/null +++ b/roles/munin/tasks/install.yml @@ -0,0 +1,48 @@ +- 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 + tags: + - download + when: is_debuntu | bool + +- name: "Install 2 packages: munin, munin-node (OS's other than debuntu)" + package: + name: + - munin + - munin-node + state: present + tags: + - download + when: not is_debuntu + +- name: Install /etc/munin/munin.conf and Apache's munin24.conf, from templates + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: 0644 + with_items: + - { src: 'munin.conf.j2', dest: '/etc/munin/munin.conf' } + - { src: 'munin24.conf.j2', dest: '/etc/{{ apache_config_dir }}/munin24.conf' } + +- name: Establish username/password Admin/changeme in /etc/munin/munin-htpasswd + htpasswd: + path: /etc/munin/munin-htpasswd + name: Admin + password: changeme + create: yes + state: present + +- name: Add 'munin_installed' variable values to {{ iiab_installed }} + lineinfile: + dest: "{{ iiab_installed }}" + regexp: '^munin_installed' + line: 'munin_installed' + state: present diff --git a/roles/munin/tasks/main.yml b/roles/munin/tasks/main.yml index 054d0de78..7a0857f42 100644 --- a/roles/munin/tasks/main.yml +++ b/roles/munin/tasks/main.yml @@ -1,116 +1,7 @@ -- 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 - tags: - - download - when: is_debuntu | bool +- name: Install munin + include_tasks: install.yml + when: munin_install | bool and not munin_installed is defined -- name: "Install 2 packages: munin, munin-node (OS's other than debuntu)" - package: - name: - - munin - - munin-node - state: present - tags: - - download - when: not is_debuntu - -##### nginx only ##### -- name: Install /etc/munin/munin.conf and Apache's munin24.conf, from templates - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - owner: root - group: root - mode: 0644 - with_items: - - { src: 'munin.conf.j2', dest: '/etc/munin/munin.conf' } - - { src: 'munin24-nginx.conf.j2', dest: '/etc/nginx/conf.d/munin24-nginx.conf' } - -- name: Establish username/password Admin/changeme in /etc/munin/munin-htpasswd - htpasswd: - path: /etc/munin/munin-htpasswd - name: Admin - password: changeme - create: yes - state: present - -- name: Enable & Start munin-node systemd service - service: - name: munin-node - enabled: yes - state: started - when: munin_enabled | bool - -- name: Disable munin-node service if not munin_enabled - service: - name: munin-node - enabled: no - state: stopped - when: not munin_enabled - -- 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 | bool - -- name: Create symlink for awstats.pl from cgi-bin/awstats/awstats.pl to ../ so that the old apache links to awstats will work after change to nginx - file: - src: /usr/lib/cgi-bin/awstats.pl - path: /usr/lib/cgi-bin/awstats/awstats.pl - state: link - -- name: Install /etc/awstats/awstats.schoolserver.conf - template: - src: awstats.schoolserver.conf.j2 - dest: /etc/awstats/awstats.schoolserver.conf - owner: root - group: root - mode: 0644 - when: awstats_enabled | bool - -- name: Create a symlink /etc/awstats/awstats.conf for access by IP address - file: - src: /etc/awstats/awstats.schoolserver.conf - path: /etc/awstats/awstats.conf - state: link - when: awstats_enabled | bool - -- name: On first enabling of AWStats, summarize httpd logs up to now (OS's other than debuntu) - shell: /bin/perl /usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=schoolserver -update - when: awstats_enabled and not is_debuntu - -- name: On first enabling of AWStats, summarize httpd logs up to now (debuntu) - shell: /usr/bin/perl /usr/lib/cgi-bin/awstats.pl -config=schoolserver -update - when: awstats_enabled and is_debuntu - -- name: Add 'munin' variable values to {{ iiab_ini_file }} - ini_file: - path: "{{ iiab_ini_file }}" - section: munin - option: "{{ item.option }}" - value: "{{ item.value }}" - with_items: - - option: name - value: Munin - - option: description - value: '"Munin is a networked resource monitoring tool that can help analyze resource trends and \"what just happened to kill our performance?\" problems."' - - option: installed - value: "{{ munin_install }}" - - option: enabled - value: "{{ munin_enabled }}" +- name: Enable munin + include_tasks: enable.yml + when: munin_install | bool or munin_installed is defined