Assign host to hostgorup via global variable

Hi,
I just want to add my host to multiple hostgroups base on the variable. My configuration like this:

object Host "host1" {
  import "generic-host"
  address = "host1.mydomain.com"
  vars.os =  [ "ntp.servers" , "linux.servers" ]
}

And my hostgroups configuration:

object HostGroup "ntp-servers" {
  display_name = "NTP Servers"

  assign where match("ntp.servers", host.vars.os)
}
----------
object HostGroup "linux-servers" {
  display_name = "Linux"

  assign where host.vars.os == "linux.servers"
}

But it not working, in my host details (in icinga2 web) it’s showing there’s no hostgroups.
But If I just put 1 value for variable, like:

vars.os =  "ntp.servers"
-------
or
vars.os =  "linux.servers"

then it works, but only for 1 hostgroup.
I’m able to assign this host to multiple group directly on groups variable:

  groups = ["ntp-servers", "wans"]

but I will use the vars.host.os variable for other services rule.
Any one can help please?

Haven’t tested it:

assign where “linux.servers” in host.vars.os

1 Like