diff --git a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 index 73f0323e5e..c0f625a8b8 100644 --- a/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 +++ b/roles/nagios_server/templates/nagios/hostgroups/all.cfg.j2 @@ -9,7 +9,7 @@ define hostgroup{ hostgroup_name {{ key }} alias {{ key }} - members {% for host in groups[key] %}{% if hostvars[host].env == 'staging' %}{{host}}, {% endif %}{% endfor %} + members {% for host in groups[key] %}{% if (hostvars[host].env is defined) and (hostvars[host].env == 'staging') %} {{host}}, {% endif %} {% endfor %} }