Commit 027c6f2f authored by Chris Croome's avatar Chris Croome

Merge branch 'refactor' into 'master'

Refactor

See merge request !1
parents 014f926c c30fdef6
Pipeline #8125 passed with stage
in 25 seconds
......@@ -2,31 +2,57 @@
Ansible role for configuring a Debian or Ubuntu server as a munin Node (client).
See [the defaults file](defaults/main.yml) for the settings.
Assuming you have a YAML `hosts.yml` file then you should add entries something like this to it:
```yml
---
all:
children:
bionic_servers:
buster_servers:
vars:
munin_servers:
- "{{ groups['munin_servers'] }}"
hosts:
example.org:
vars:
munin_apache: true
munin_opcache: true
munin_phpfpm: false
munin_plugins_disabled:
- entropy
- name: multips
- name: multips_memory
munin_plugins_enabled:
- name: cpu
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: mysql_commands
file: mysql_
- name: mysql_connections
file: mysql_
example.org.uk:
vars:
munin_nginx: true
munin_opcache: true
munin_phpfpm: true
munin_multips_processes: apache2 php mysqld
munin_multips_memory_processes: apache2 php-fpm7.3 mysqld
munin_plugins_enabled:
- name: multips
- name: multips_memory
- name: phpfpm_multi_average
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_connections
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_memory
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_processes
dir: /usr/local/share/munin/plugins
munin_servers:
hosts:
monitor.webarch.net:
ipv4_addr: 81.95.52.37
...
```
In order to use this role.
Some inspiration for this role was taken from
[systemli](https://github.com/systemli/ansible-role-munin-node) and
[geerlingguy](https://github.com/geerlingguy/ansible-role-munin-node) roles.
---
munin_apt_all: true
munin_disk: true
munin_entropy: false
# munin_multips: true
# munin_multips_processes: apache2 php mysqld
# munin_multips_memory: true
# munin_multips_memory_processes: apache2 php-fpm7.3 mysqld
# munin_nginx: false
# munin_apache: false
# munin_phpfpm: false
# If the following two variabled are not set then the phpfpm_version.yml
# tasks will automatically set values for these variables
# munin_phpfpm_version: 7.3
# munin_phpfpm_socket: /var/run/php/php7.3-fpm.sock
# munin_phpfpm_multi: false
# munin_opcache: false
#
# The following two defaults are for a [WSH](https://git.coop/webarch/wsh)
# Debian Buster server.
munin_multips_processes: apache2 php mysqld
munin_multips_memory_processes: apache2 php-fpm7.3 mysqld
#
# Plugins where the symlink and file are the same just need a name, plugins
# that have a different file need file: and plugins not in
# /usr/share/munin/plugins need a dir:
munin_plugins_disabled:
- name: entropy
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: nginx_request
- name: nginx_status
- name: phpfpm_average
dir: /usr/local/share/munin/plugins
- name: phpfpm_connections
dir: /usr/local/share/munin/plugins
- name: phpfpm_memory
dir: /usr/local/share/munin/plugins
- name: phpfpm_processes
dir: /usr/local/share/munin/plugins
- name: phpfpm_status
dir: /usr/local/share/munin/plugins
munin_plugins_enabled:
- name: apt_all
- name: cpu
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: df
- name: df_inode
- name: diskstats
- name: fail2ban
- name: forks
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: fw_packets
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: interrupts
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: load
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: open_files
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: open_inodes
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: swap
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: threads
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: uptime
dir: /usr/lib/munin-c/plugins
file: munin-plugins-c
- name: multips
- name: multips_memory
- name: php_opcache_memoryusage
dir: /usr/local/share/munin/plugins
- name: php_opcache_restarts
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_average
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_connections
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_memory
dir: /usr/local/share/munin/plugins
- name: phpfpm_multi_processes
dir: /usr/local/share/munin/plugins
- name: mysql_commands
file: mysql_
- name: mysql_connections
file: mysql_
- name: mysql_files_tables
file: mysql_
- name: mysql_innodb_bpool
file: mysql_
- name: mysql_innodb_bpool_act
file: mysql_
- name: mysql_innodb_insert_buf
file: mysql_
- name: mysql_innodb_io
file: mysql_
- name: mysql_innodb_io_pend
file: mysql_
- name: mysql_innodb_log
file: mysql_
- name: mysql_innodb_rows
file: mysql_
- name: mysql_innodb_semaphores
file: mysql_
- name: mysql_innodb_tnx
file: mysql_
- name: mysql_myisam_indexes
file: mysql_
- name: mysql_network_traffic
file: mysql_
- name: mysql_qcache
file: mysql_
- name: mysql_qcache_mem
file: mysql_
- name: mysql_select_types
file: mysql_
- name: mysql_slow
file: mysql_
- name: mysql_sorts
file: mysql_
- name: mysql_table_locks
file: mysql_
- name: mysql_tmp_tables
file: mysql_
...
---
- name: Set a fact for the list of Munin Apache plugins
set_fact:
munin_apache_plugins:
- apache_accesses
- apache_processes
- apache_volume
when: munin_apache_plugins is not defined
tags:
- munin
- name: Munin Apache plugins disabled
file:
path: "/etc/munin/plugins/{{ plugin }}"
state: absent
loop: "{{ munin_apache_plugins }}"
loop_control:
loop_var: plugin
when: munin_apache == False
tags:
- munin
- name: Munin Apache plugins enabled
file:
path: "/etc/munin/plugins/{{ plugin }}"
src: "/usr/share/munin/plugins/{{ plugin }}"
state: link
loop: "{{ munin_apache_plugins }}"
loop_control:
loop_var: plugin
when: munin_apache == True
tags:
- munin
...
---
- name: "Debian distro set to {{ munin_debian_version }} for munin apt_all plugin"
lineinfile:
state: present
line: "my @releases = ('{{ munin_debian_version }}');"
regexp: "^my @releases"
dest: /usr/share/munin/plugins/apt_all
tags:
- munin
- name: Munin apt_all plugin disabled
file:
path: /etc/munin/plugins/apt_all
src: /usr/share/munin/plugins/apt_all
state: link
when: munin_apt_all == False
tags:
- munin
- name: Munin apt_all plugin enabled
file:
path: /etc/munin/plugins/apt_all
src: /usr/share/munin/plugins/apt_all
state: link
when: munin_apt_all == True
tags:
- munin
...
---
- name: Contrib plugins present
git:
repo: https://github.com/munin-monitoring/contrib.git
dest: /usr/local/src/munin_contrib
clone: true
update: true
tags:
- munin
- name: Selected contrib plugins in place
copy:
src: "/usr/local/src/munin_contrib/plugins/{{ plugin.dir }}/{{ plugin.name }}"
dest: "/usr/local/share/munin/plugins/{{ plugin.name }}"
mode: 0755
remote_src: true
loop:
- name: docker_cpu
dir: docker
- name: docker_memory
dir: docker
loop_control:
loop_var: plugin
tags:
- munin
...
---
- name: Set a fact for the list of Munin disk plugins
set_fact:
munin_disk_plugins:
- df
- df_inode
- diskstats
when: munin_disk_plugins is not defined
tags:
- munin
- name: Munin disk plugins disabled
file:
path: "/etc/munin/plugins/{{ plugin }}"
state: absent
when: munin_disk == False
loop: "{{ munin_disk_plugins }}"
loop_control:
loop_var: plugin
tags:
- munin
- name: Munin disk plugins enabled
file:
path: "/etc/munin/plugins/{{ plugin }}"
src: "/usr/share/munin/plugins/{{ plugin }}"
state: link
when: munin_disk == True
loop: "{{ munin_disk_plugins }}"
loop_control:
loop_var: plugin
tags:
- munin
...
---
- name: Munin entropy plugin disabled
file:
path: /etc/munin/plugins/entropy
state: absent
when: munin_entropy == False
tags:
- munin
- name: Munin entropy plugin enabled
file:
path: /etc/munin/plugins/entropy
src: /usr/share/munin/entropy
state: link
when: munin_entropy == True
tags:
- munin
...
......@@ -2,6 +2,7 @@
- name: Check /etc/debian_version
shell: "lsb_release -c | awk '{ print $2 }'"
register: munin_debian_version_check
check_mode: false
changed_when: false
tags:
- munin
......@@ -32,12 +33,12 @@
- munin-node
- munin-plugins-core
- munin-plugins-extra
- munin-plugins-c
- libwww-perl
- time
- libcache-cache-perl
- libcache-memcached-perl
state: latest
update_cache: true
state: present
register: munin_node_packages
tags:
- munin
......@@ -49,115 +50,51 @@
tags:
- munin
- name: Include apt_all tasks
include_tasks: apt_all.yml
when: munin_apt_all is defined
- name: "Debian distro set to {{ munin_debian_version }} for munin apt_all plugin"
lineinfile:
state: present
line: "my @releases = ('{{ munin_debian_version }}');"
regexp: "^my @releases"
dest: /usr/share/munin/plugins/apt_all
tags:
- munin
- name: Include disk tasks
include_tasks: disk.yml
when: munin_disk is defined
- name: Tasks for specific plugins included
include_tasks: "{{ tasks }}"
loop:
- contrib.yml
- opcache.yml
- phpfpm.yml
- phpfpm_multi.yml
loop_control:
loop_var: tasks
tags:
- munin
- name: Include entropy tasks
include_tasks: entropy.yml
when: munin_entropy is defined
tags:
- munin
- name: Include multips tasks
include_tasks: multips.yml
when: munin_multips is defined
tags:
- munin
- name: Include multips_memory tasks
include_tasks: multips_memory.yml
when: munin_multips_memory is defined
tags:
- munin
- name: Set a fact for munin_nginx is it is not defined but Nginx is installed
set_fact:
munin_nginx: true
when: ( munin_nginx is not defined ) and ( "nginx" in ansible_facts.packages )
tags:
- munin
- name: Include Nginx tasks
include_tasks: nginx.yml
when: munin_nginx is defined
tags:
- munin
- name: Set a fact for munin_apache is it is not defined but Apache is installed
set_fact:
munin_apache: true
when: ( munin_apache is not defined ) and ( "apache2" in ansible_facts.packages )
tags:
- munin
- name: Include Apache tasks
include_tasks: apache.yml
when: munin_apache is defined
tags:
- munin
- name: Include PHP-FPM tasks
include_tasks: phpfpm.yml
when: munin_phpfpm is defined
tags:
- munin
- name: Include OPCache tasks
include_tasks: opcache.yml
when: munin_opcache is defined
- name: Loop to disable plugins
file:
path: "/etc/munin/plugins/{{ plugin.name }}"
state: absent
when: ( munin_plugins_disabled is defined ) and ( munin_plugins_disabled != [] )
loop: "{{ munin_plugins_disabled }}"
loop_control:
loop_var: plugin
tags:
- munin
- name: MySQL / MariaDB checks
block:
- name: Check if mysql-server is installed
shell: "dpkg -s mysql-server && echo PRESENT || echo ABSENT"
register: munin_mysql_server
tags:
- munin
- name: Check if mariadb-server is installed
shell: "dpkg -s mariadb-server && echo PRESENT || echo ABSENT"
register: munin_mariadb_server
tags:
- munin
- name: Set a fact for munin_mysql is it is not defined but MySQL or MariaBD is installed
set_fact:
munin_mysql: true
when: ( munin_mysql_server is defined and munin_mysql_server.stdout == "PRESENT" ) or ( munin_mariadb_server is defined and munin_mariadb_server.stdout == "PRESENT" )
tags:
- munin
when: munin_mysql is not defined
- name: Include MySQL tasks
include_tasks: mysql.yml
when: munin_mysql is defined
- name: Loop to enable plugins
file:
path: "/etc/munin/plugins/{{ plugin.name }}"
src: '{{ plugin.dir | default("/usr/share/munin/plugins") }}/{{ plugin.file | default(plugin.name) }}'
state: link
force: false
when: ( munin_plugins_enabled is defined ) and ( munin_plugins_enabled != [] )
loop: "{{ munin_plugins_enabled }}"
loop_control:
loop_var: plugin
tags:
- munin
- name: If users are defined
block:
- name: Include PHP-FPM multiuser tasks
include_tasks: phpfpm_multi.yml
when: munin_phpfpm_multi is defined
tags:
- munin
when: ( users is defined ) and ( users != "" )
- name: Munin node config file present
template:
src: templates/munin-node.conf.j2
......
---
- name: Munin multips plugin disabled
file:
path: /etc/munin/plugins/multips
state: absent
when: munin_multips == False
tags:
- munin
- name: Munin multips plugin enabled
file:
path: /etc/munin/plugins/multips
src: /usr/share/munin/plugins/multips
state: link
when: munin_multips == True
tags:
- munin
...
---
- name: Munin multips_memory plugin disabled
file:
path: /etc/munin/plugins/multips_memory
state: absent
when: munin_multips_memory == False
tags:
- munin
- name: Munin multips_memory plugin enabled
file:
path: /etc/munin/plugins/multips_memory
src: /usr/share/munin/plugins/multips_memory
state: link
when: munin_multips_memory == True
tags:
- munin
...
---
- name: Set a fact for the list of MySQL plugins
set_fact:
munin_mysql_plugins:
- commands
- connections
- files_tables
- innodb_bpool
- innodb_bpool_act
- innodb_insert_buf
- innodb_io
- innodb_io_pend
- innodb_log
- innodb_rows
- innodb_semaphores
- innodb_tnx
- myisam_indexes
- network_traffic
- qcache
- qcache_mem
- select_types
- slow
- sorts
- table_locks
- tmp_tables
when: munin_mysql_plugins is not defined
tags:
- munin
- name: Munin MySQL plugins disabled
file:
path: "/etc/munin/plugins/mysql_{{ plugin }}"
state: absent
loop: "{{ munin_mysql_plugins }}"
loop_control:
loop_var: plugin
when: munin_mysql == False
tags:
- munin
- name: Munin MySQL plugins enabled
file:
path: "/etc/munin/plugins/mysql_{{ plugin }}"
src: /usr/share/munin/plugins/mysql_
state: link
loop: "{{ munin_mysql_plugins }}"
loop_control:
loop_var: plugin
when: munin_mysql == True
tags:
- munin
...
---
- name: Set a fact for the list of Munin Nginx plugins
set_fact:
munin_nginx_plugins:
- nginx_request
- nginx_status
when: munin_nginx_plugins is not defined
tags:
- munin
- name: Disable Munin Nginx plugins
file:
path: "/etc/munin/plugins/{{ plugin }}"
state: absent
loop: "{{ munin_nginx_plugins }}"
loop_control:
loop_var: plugin
when: munin_nginx == False
tags:
- munin
- name: Enable Munin Nginx plugins
file:
src: "/usr/share/munin/plugins/{{ plugin }}"
dest: "/etc/munin/plugins/{{ plugin }}"
state: link
loop: "{{ munin_nginx_plugins }}"
loop_control:
loop_var: plugin
when: munin_nginx == True
tags:
- munin
...
---
- name: Munin OPCache disabled
block:
- name: OPCache Munin plugin disabled
file:
path: "/etc/munin/plugins/{{ item }}"
state: absent
loop:
- php_opcache_memoryusage
- php_opcache_restarts
tags:
- munin
- name: OPCache Munin plugin absent
file:
path: "/usr/local/share/munin/plugins/{{ item }}"
state: absent
loop:
- php_opcache_memoryusage
- php_opcache_restarts
- name: OPCache PHP scripts absent
file:
path: "/usr/local/src/munin_opcache/src/scripts/{{ item }}"
state: absent
loop:
- munin_opcache.php
- opc.php
tags:
- munin
- name: OPCache source absent
file:
path: /usr/local/src/munin_opcache
state: absent
tags:
- munin
when: munin_opcache == False
- name: Munin OPCache enabled
block:
- name: OPCache plugin source present
git:
repo: https://github.com/webarch-coop/munin_opcache.git
dest: /usr/local/src/munin_opcache
clone: true
update: true
tags:
- munin
- name: /var/www/localhost directory present
file:
path: /var/www/localhost
state: directory
tags:
- munin
- name: OPCache PHP scripts in place
copy:
src: "/usr/local/src/munin_opcache/src/scripts/{{ item }}"
dest: "/var/www/localhost/{{ item }}"
remote_src: true
mode: 0755
loop:
- munin_opcache.php
- opc.php
tags:
- munin
- name: OPCache Munin plugin present
copy:
src: "/usr/local/src/munin_opcache/src/plugins/{{ item }}"
dest: "/usr/local/share/munin/plugins/{{ item }}"
remote_src: true
mode: 0755
loop:
- php_opcache_memoryusage
- php_opcache_restarts
tags:
- munin
- name: OPCache Munin plugin enabled
file:
path: "/etc/munin/plugins/{{ item }}"
src: "/usr/local/share/munin/plugins/{{ item }}"
state: link
loop:
- php_opcache_memoryusage
- php_opcache_restarts
tags:
- munin
when: munin_opcache == True
- name: OPCache plugin source present
git:
repo: https://github.com/webarch-coop/munin_opcache.git
dest: /usr/local/src/munin_opcache
clone: true
update: true
tags:
- munin
- name: /var/www/localhost directory present
file:
path: /var/www/localhost
state: directory
tags:
- munin
- name: OPCache PHP scripts in place
copy:
src: "/usr/local/src/munin_opcache/src/scripts/{{ item }}"
dest: "/var/www/localhost/{{ item }}"