From 3d9d816f834a1146c1daa74e078ae09c97e1eaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lecour?= Date: Sat, 20 May 2017 00:23:58 +0200 Subject: [PATCH] postgresql: add munin/nrpe artefacts only if needed --- postgresql/tasks/munin.yml | 12 ++++++++++++ postgresql/tasks/nrpe.yml | 38 +++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/postgresql/tasks/munin.yml b/postgresql/tasks/munin.yml index 9baf0e79..e576b4cd 100644 --- a/postgresql/tasks/munin.yml +++ b/postgresql/tasks/munin.yml @@ -1,4 +1,14 @@ --- +- name: Are Munin plugins present in /etc ? + stat: + path: /etc/munin/plugins + register: etc_munin_plugins + +- name: Are Munin plugins present in /usr/share ? + stat: + path: /usr/share/munin/plugins + register: usr_share_munin_plugins + - name: Add Munin plugins for PostgreSQL file: state: link @@ -11,6 +21,7 @@ - postgres_users - postgres_xlog notify: restart munin-node + when: etc_munin_plugins.stat.exists and usr_share_munin_plugins.stat.exists - name: Add Munin plugins for PostgreSQL (for specific databases) file: @@ -21,3 +32,4 @@ - ['postgres_cache_', 'postgres_connections_', 'postgres_locks_', 'postgres_querylength_', 'postgres_scans_', 'postgres_size_', 'postgres_transactions_', 'postgres_tuples_'] - '{{postgresql_databases}}' notify: restart munin-node + when: etc_munin_plugins.stat.exists and usr_share_munin_plugins.stat.exists diff --git a/postgresql/tasks/nrpe.yml b/postgresql/tasks/nrpe.yml index f609f71e..968f2fcc 100644 --- a/postgresql/tasks/nrpe.yml +++ b/postgresql/tasks/nrpe.yml @@ -14,19 +14,27 @@ name: python-psycopg2 state: present -- name: Create nrpe user - become: yes - become_user: postgres - postgresql_user: - name: nrpe - password: '{{ postgresql_nrpe_password.stdout }}' - no_password_changes: yes - register: postgresql_create_nrpe_user +- name: Is nrpe present ? + stat: + path: /etc/nagios/nrpe.d/evolix.cfg + register: nrpe_evolix_config -- name: Add NRPE check - lineinfile: - name: /etc/nagios/nrpe.d/evolix.cfg - regexp: '^command\[check_pgsql\]=' - line: 'command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H localhost -l nrpe -p "{{postgresql_nrpe_password.stdout}}"' - when: postgresql_create_nrpe_user.changed - notify: restart nagios-nrpe-server +- block: + - name: Create nrpe user + become: yes + become_user: postgres + postgresql_user: + name: nrpe + password: '{{ postgresql_nrpe_password.stdout }}' + no_password_changes: yes + register: postgresql_create_nrpe_user + when: nrpe_evolix_config.stat.exists + + - name: Add NRPE check + lineinfile: + name: /etc/nagios/nrpe.d/evolix.cfg + regexp: '^command\[check_pgsql\]=' + line: 'command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H localhost -l nrpe -p "{{postgresql_nrpe_password.stdout}}"' + notify: restart nagios-nrpe-server + when: postgresql_create_nrpe_user.changed + when: nrpe_evolix_config.stat.exists