postgresql: add munin/nrpe artefacts only if needed

This commit is contained in:
Jérémy Lecour 2017-05-20 00:23:58 +02:00
parent 283953a69f
commit 3d9d816f83
2 changed files with 35 additions and 15 deletions

View file

@ -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 - name: Add Munin plugins for PostgreSQL
file: file:
state: link state: link
@ -11,6 +21,7 @@
- postgres_users - postgres_users
- postgres_xlog - postgres_xlog
notify: restart munin-node 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) - name: Add Munin plugins for PostgreSQL (for specific databases)
file: file:
@ -21,3 +32,4 @@
- ['postgres_cache_', 'postgres_connections_', 'postgres_locks_', 'postgres_querylength_', 'postgres_scans_', 'postgres_size_', 'postgres_transactions_', 'postgres_tuples_'] - ['postgres_cache_', 'postgres_connections_', 'postgres_locks_', 'postgres_querylength_', 'postgres_scans_', 'postgres_size_', 'postgres_transactions_', 'postgres_tuples_']
- '{{postgresql_databases}}' - '{{postgresql_databases}}'
notify: restart munin-node notify: restart munin-node
when: etc_munin_plugins.stat.exists and usr_share_munin_plugins.stat.exists

View file

@ -14,6 +14,12 @@
name: python-psycopg2 name: python-psycopg2
state: present state: present
- name: Is nrpe present ?
stat:
path: /etc/nagios/nrpe.d/evolix.cfg
register: nrpe_evolix_config
- block:
- name: Create nrpe user - name: Create nrpe user
become: yes become: yes
become_user: postgres become_user: postgres
@ -22,11 +28,13 @@
password: '{{ postgresql_nrpe_password.stdout }}' password: '{{ postgresql_nrpe_password.stdout }}'
no_password_changes: yes no_password_changes: yes
register: postgresql_create_nrpe_user register: postgresql_create_nrpe_user
when: nrpe_evolix_config.stat.exists
- name: Add NRPE check - name: Add NRPE check
lineinfile: lineinfile:
name: /etc/nagios/nrpe.d/evolix.cfg name: /etc/nagios/nrpe.d/evolix.cfg
regexp: '^command\[check_pgsql\]=' regexp: '^command\[check_pgsql\]='
line: 'command[check_pgsql]=/usr/lib/nagios/plugins/check_pgsql -H localhost -l nrpe -p "{{postgresql_nrpe_password.stdout}}"' 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 notify: restart nagios-nrpe-server
when: postgresql_create_nrpe_user.changed
when: nrpe_evolix_config.stat.exists