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 %}