-1

I would like to install Nagios plugins based on server role. The solution below works but I'm sure there is a more elegant/recommended way to achieve the same - any help would be appreciated. I don't like this explicit dictionary in merge statement and nested for loop.

Pillar:

nagios:
  nrpe:
    allowed_hosts: 127.0.0.1
    plugins:
      all:
        - nagios-plugins-disk
        - nagios-plugins-load
        - nagios-plugins-procs
        - nagios-plugins-swap
      db:
        - nagios-plugins-mysql

State:

{% set plugins = salt['grains.filter_by']({
'db': { 'db': salt['pillar.get']('nagios:nrpe:plugins:db') }
}, grain='role', merge={ 'all': salt['pillar.get']('nagios:nrpe:plugins:all') }) %}

nrpe_plugins_all:
  pkg.installed:
    - pkgs:
{%- for plugin in plugins.values() %}
{%- for pkg in plugin %}
    - {{ pkg }}
{%- endfor %}
{%- endfor %}
HTF
  • 3,148
  • 14
  • 52
  • 82

1 Answers1

0

A different approach would be to use grains to identify which hosts should have nagios and various nagios plugins:

Minion Grains (/etc/salt/grains)

roles:
 - nagios
 - nagios_mysql

State Top File

base:
  'G@roles:nagios':
    - nagios/npre_install_basic
  'G@roles:nagios_mysql':
    - nagios/npre_install_mysql

Nagios State Files

npre_install_basic:
  pkg.installed:
    - pkgs:
        - nagios-plugins-disk
        - nagios-plugins-load
        - nagios-plugins-procs
        - nagios-plugins-swap
    - require:
      - pkg: nagios

Nagios State Files

npre_install_mysql:
  pkg.installed:
    - pkgs:
        - nagios-plugins-mysql
    - require:
      - pkg: nagios
chugadie
  • 201
  • 1
  • 5
  • Thanks for your reply. I like this approach but this will install only `nagios-plugins-mysql` plugin on servers with `nagios_mysql` role so there should be some extra logic to merge both, basic and extra plugin(s). – HTF Oct 30 '15 at 15:58
  • You can add multiple roles per node/minion. The grains key "roles" is an array. – chugadie Oct 30 '15 at 22:08