{%- if services is defined %}
  {%- for role in services %}
    {%- if services[role] is defined %}
      {%- for service in services[role] %}
        {%- if role == "core" -%}
          {% set role_restriction = '' %}
        {%- else -%}
          {% set role_restriction = '&& "'+role+'" in host.vars.roles' %}
        {%- endif %}
apply Service "nrpe_service_{{role}}_{{ service }}"{
  import "generic-service"

  check_command = "nrpe"
  vars.nrpe_command = "check_service"
  vars.nrpe_arguments = [ "{{ service }}" ]

  assign where host.address {{role_restriction}}
}
      {%- endfor -%}
    {%- endif -%}
  {%- endfor -%}
{%- endif -%}