# Create Service02 for all Hosts that have Service01

**URL:** <https://community.icinga.com/t/create-service02-for-all-hosts-that-have-service01/12881>\
**Category:** Icinga 2\
**Tags:** icinga2\
**Created:** [November 10, 2023, 3:24pm UTC](https://community.icinga.com/t/create-service02-for-all-hosts-that-have-service01/12881 "2023-11-10T15:24:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![markusr](https://community.icinga.com/letter_avatar_proxy/v4/letter/m/34f0e0/32.png) [@markusr](https://community.icinga.com/u/markusr)\
**Post date:** [November 10, 2023, 3:24pm UTC](https://community.icinga.com/t/create-service02-for-all-hosts-that-have-service01/12881/1 "2023-11-10T15:24:24Z")

</div>

Hi 👋

I’m not sure if my intention is unusual, but I couldn’t find an answer to my question in the documentation and thought maybe I can find an answer here. I have a host and a service:

```auto
object Host "example.com" {
  import "generic-host"
}

object Service "service01" {
  import "generic-service"
  host_name = "example.com"
  display_name = "service01"
  check_command = "command01"

  vars.key01 = 500
}

```

This works so far, the host and the service are available in Icinga. Now I would like to use “assign where” to create a second service. The second service should be created for each host if:

- The host has a service with name “service01”
- The corresponding “service01” has the variable “key01”

I was thinking something like that:

```auto
apply Service "service02" {
  import "generic-service"
  display_name = "service02"
  check_command = "command02"

  assign where "service01" in host.services
}

```

But this ends with:

```auto
[2023-11-10 16:19:08 +0100] critical/config: Error: Invalid field access (for value of type 'Host'): 'services'

```

And that doesn’t take into account the fact that I also want to check the variable.

Best,  
Markus

---

<div class="post-metadata">

**Author:** ![Al2Klimov](https://community.icinga.com/user_avatar/community.icinga.com/al2klimov/32/959_2.png) [@Al2Klimov](https://community.icinga.com/u/Al2Klimov)\
**Post date:** [November 10, 2023, 4:26pm UTC](https://community.icinga.com/t/create-service02-for-all-hosts-that-have-service01/12881/2 "2023-11-10T16:26:06Z")

</div>

Hello Markus!

First of all, if you have a service01 on more than one host, consider an apply rule for that. Such will have an assign rule you can copy to service02 and include the key01 there. But the latter will have to reside inside the host.

Best,  
A/K

---

<div class="post-metadata">

**Author:** ![lorenz](https://community.icinga.com/user_avatar/community.icinga.com/lorenz/32/7666_2.png) [@lorenz](https://community.icinga.com/u/lorenz)\
**Post date:** [November 12, 2023, 1:01pm UTC](https://community.icinga.com/t/create-service02-for-all-hosts-that-have-service01/12881/3 "2023-11-12T13:01:58Z")

</div>

Hi @markusr,  
I am not completely sure about this, but I think it is not possible to create this the way you tried here.

A `Service` is not part of a `Host` (as would be suggested with `host.services`) but it is almost the other way round. A `Service` knows it’s `Host` (`host_name` attribute).  
Since `apply` rules can not reference other `Service`s (I believe), setting up a `Service` by referencing another `Service` is not possible.

The way around this would be (as @Al2Klimov suggested in a way) to change your data model and put all the necessary information in the host (via the `vars` dictionary for example) and assign the two services independently but maybe using the same condition.
