From 56670cd032559ea715cc3186ad0adbd33dd3a887 Mon Sep 17 00:00:00 2001 From: Niklas Yann Wettengel Date: Mon, 20 Mar 2017 21:09:02 +0100 Subject: [PATCH] install_monitoring: split different monitoring solutions into different task files --- .../tasks/install_ffmyk-influx.yml | 48 +++++ .../tasks/install_munin.yml | 55 ++++++ .../tasks/install_vnstat.yml | 64 +++++++ roles/install_monitoring/tasks/main.yml | 164 +----------------- 4 files changed, 171 insertions(+), 160 deletions(-) create mode 100644 roles/install_monitoring/tasks/install_ffmyk-influx.yml create mode 100644 roles/install_monitoring/tasks/install_munin.yml create mode 100644 roles/install_monitoring/tasks/install_vnstat.yml diff --git a/roles/install_monitoring/tasks/install_ffmyk-influx.yml b/roles/install_monitoring/tasks/install_ffmyk-influx.yml new file mode 100644 index 0000000..3177d84 --- /dev/null +++ b/roles/install_monitoring/tasks/install_ffmyk-influx.yml @@ -0,0 +1,48 @@ +--- +- name: create ffmyk-influx folder + file: + path: /opt/ffmyk-influx + state: directory + +- name: copy ffmyk-influx daemon.sh + copy: + src: ffmyk-influx/daemon.sh + dest: /opt/ffmyk-influx/daemon.sh + mode: 0755 + +- name: copy ffmyk-influx php.ini + copy: + src: ffmyk-influx/php.ini + dest: /opt/ffmyk-influx/php.ini + +- name: copy ffmyk-influx systemd service + copy: + src: ffmyk-influx/ffmyk-influx.service + dest: /etc/systemd/system/ffmyk-influx.service + +- name: copy ffmyk-influx dhcp.php + template: + src: ffmyk-influx/dhcp.php.j2 + dest: /opt/ffmyk-influx/dhcp.php + +- name: copy ffmyk-influx fastd.php + template: + src: ffmyk-influx/fastd.php.j2 + dest: /opt/ffmyk-influx/fastd.php + +- name: copy ffmyk-influx func.php + template: + src: ffmyk-influx/func.php.j2 + dest: /opt/ffmyk-influx/func.php + +- name: copy ffmyk-influx traffic.php + template: + src: ffmyk-influx/traffic.php.j2 + dest: /opt/ffmyk-influx/traffic.php + +- name: start and enable ffmyk-influx.service + systemd: + name: ffmyk-influx.service + enabled: yes + state: started + diff --git a/roles/install_monitoring/tasks/install_munin.yml b/roles/install_monitoring/tasks/install_munin.yml new file mode 100644 index 0000000..cf2bfc2 --- /dev/null +++ b/roles/install_monitoring/tasks/install_munin.yml @@ -0,0 +1,55 @@ +--- +- name: install munin + pacman: + name: munin-node + state: present + +- name: copy munin-node config + template: + src: munin-node.conf.j2 + dest: /etc/munin/munin-node.conf + +- name: copy fastd plugin + copy: + src: munin/munin_fastd_plugin + dest: /usr/lib/munin/plugins/fastd_ + mode: 0755 + +- name: copy dhcp-pool plugin + copy: + src: munin/munin_dhcp_pool_plugin + dest: /usr/lib/munin/plugins/dhcp-pool + mode: 0755 + +- name: copy fastd plugin config + copy: + src: munin/munin_fastd_conf + dest: /etc/munin/plugin-conf.d/fastd + +- name: copy global config + copy: + src: munin/munin_global_conf + dest: /etc/munin/plugin-conf.d/global + +- name: install netstat + pacman: + name: net-tools + state: present + +- name: install perl-lwp-protocol-https + pacman: + name: perl-lwp-protocol-https + state: present + +- name: enable munin plugins + file: + path: /etc/munin/plugins/{{ item.name }} + src: /usr/lib/munin/plugins/{{ item.plugin | default( item.name ) }} + state: link + with_items: "{{ munin_node_plugins }}" + +- name: start and enable munin-node + systemd: + name: munin-node.service + enabled: yes + state: started diff --git a/roles/install_monitoring/tasks/install_vnstat.yml b/roles/install_monitoring/tasks/install_vnstat.yml new file mode 100644 index 0000000..0198403 --- /dev/null +++ b/roles/install_monitoring/tasks/install_vnstat.yml @@ -0,0 +1,64 @@ +--- +- name: install vnstat + pacman: + name: vnstat + state: present + +- name: start and enable vnstat service + systemd: + name: vnstat.service + enabled: yes + state: started + +- name: add interfaces to vnstat + command: /usr/bin/vnstat -u -i {{ item }} + args: + creates: '/var/lib/vnstat/{{ item }}' + with_items: + - bat0 + - ens3 + - ffmyk-mesh-vpn + - mullvad + +- name: add output folder for vnstat graphs + file: + path: /srv/http/vnstat + state: directory + +- name: install gd which is needed for graph generation + pacman: + name: gd + state: present + +- name: add bash script to generate vnstat graphs + copy: + src: vnstat.sh + dest: /usr/local/bin/vnstat.sh + mode: 0744 + +- name: add cronjob to generate vnstat graphs + cron: + name: vnstat + minute: '*/5' + user: root + cron_file: fastd-api + job: '/usr/local/bin/vnstat.sh' + +- name: add vnstat nginx config + copy: + src: vnstat + dest: /etc/nginx/sites-available/vnstat + register: nginx_config + +- name: enable vnstat nginx config + file: + src: /etc/nginx/sites-available/vnstat + dest: /etc/nginx/sites-enabled/vnstat + state: link + +- name: reload nginx + when: nginx_config.changed + systemd: + name: nginx.service + state: reloaded + diff --git a/roles/install_monitoring/tasks/main.yml b/roles/install_monitoring/tasks/main.yml index eb6b4a3..726d890 100644 --- a/roles/install_monitoring/tasks/main.yml +++ b/roles/install_monitoring/tasks/main.yml @@ -1,66 +1,6 @@ --- - name: install vnstat - pacman: - name: vnstat - state: present - -- name: start and enable vnstat service - systemd: - name: vnstat.service - enabled: yes - state: started - -- name: add interfaces to vnstat - command: /usr/bin/vnstat -u -i {{ item }} - args: - creates: '/var/lib/vnstat/{{ item }}' - with_items: - - bat0 - - ens3 - - ffmyk-mesh-vpn - - mullvad - -- name: add output folder for vnstat graphs - file: - path: /srv/http/vnstat - state: directory - -- name: install gd which is needed for graph generation - pacman: - name: gd - state: present - -- name: add bash script to generate vnstat graphs - copy: - src: vnstat.sh - dest: /usr/local/bin/vnstat.sh - mode: 0744 - -- name: add cronjob to generate vnstat graphs - cron: - name: vnstat - minute: '*/5' - user: root - cron_file: fastd-api - job: '/usr/local/bin/vnstat.sh' - -- name: add vnstat nginx config - copy: - src: vnstat - dest: /etc/nginx/sites-available/vnstat - register: nginx_config - -- name: enable vnstat nginx config - file: - src: /etc/nginx/sites-available/vnstat - dest: /etc/nginx/sites-enabled/vnstat - state: link - -- name: reload nginx - when: nginx_config.changed - systemd: - name: nginx.service - state: reloaded + include: install_vnstat.yml - name: add bash script to check internet copy: @@ -75,104 +15,8 @@ cron_file: fastd-api job: '/usr/local/bin/check_internet.sh' -- name: create ffmyk-influx folder - file: - path: /opt/ffmyk-influx - state: directory - -- name: copy ffmyk-influx daemon.sh - copy: - src: ffmyk-influx/daemon.sh - dest: /opt/ffmyk-influx/daemon.sh - mode: 0755 - -- name: copy ffmyk-influx php.ini - copy: - src: ffmyk-influx/php.ini - dest: /opt/ffmyk-influx/php.ini - -- name: copy ffmyk-influx systemd service - copy: - src: ffmyk-influx/ffmyk-influx.service - dest: /etc/systemd/system/ffmyk-influx.service - -- name: copy ffmyk-influx dhcp.php - template: - src: ffmyk-influx/dhcp.php.j2 - dest: /opt/ffmyk-influx/dhcp.php - -- name: copy ffmyk-influx fastd.php - template: - src: ffmyk-influx/fastd.php.j2 - dest: /opt/ffmyk-influx/fastd.php - -- name: copy ffmyk-influx func.php - template: - src: ffmyk-influx/func.php.j2 - dest: /opt/ffmyk-influx/func.php - -- name: copy ffmyk-influx traffic.php - template: - src: ffmyk-influx/traffic.php.j2 - dest: /opt/ffmyk-influx/traffic.php - -- name: start and enable ffmyk-influx.service - systemd: - name: ffmyk-influx.service - enabled: yes - state: started +- name: install ffmyk-influx + include: install_ffmyk-influx.yml - name: install munin - pacman: - name: munin-node - state: present - -- name: copy munin-node config - template: - src: munin-node.conf.j2 - dest: /etc/munin/munin-node.conf - -- name: copy fastd plugin - copy: - src: munin/munin_fastd_plugin - dest: /usr/lib/munin/plugins/fastd_ - mode: 0755 - -- name: copy dhcp-pool plugin - copy: - src: munin/munin_dhcp_pool_plugin - dest: /usr/lib/munin/plugins/dhcp-pool - mode: 0755 - -- name: copy fastd plugin config - copy: - src: munin/munin_fastd_conf - dest: /etc/munin/plugin-conf.d/fastd - -- name: copy global config - copy: - src: munin/munin_global_conf - dest: /etc/munin/plugin-conf.d/global - -- name: install netstat - pacman: - name: net-tools - state: present - -- name: install perl-lwp-protocol-https - pacman: - name: perl-lwp-protocol-https - state: present - -- name: enable munin plugins - file: - path: /etc/munin/plugins/{{ item.name }} - src: /usr/lib/munin/plugins/{{ item.plugin | default( item.name ) }} - state: link - with_items: "{{ munin_node_plugins }}" - -- name: start and enable munin-node - systemd: - name: munin-node.service - enabled: yes - state: started + include: install_munin.yml