How to use a vars in Director Service's display_name

I want to use the value of a custom_var as the prefix of the diaplay_name (for Hosts and Services, let’s talk about Services first). At the time, i am able to do that using a “default-service” template and it works:

template Service "default-service" {
  display_name = vars.prefix + "-" + name
}

The problem is when i change the value of the vars.prefix custom_var, if i do (in another template that inherist this one or in the host) the value of the display_name does not change. And i have vars.prefix with a value and the display_name with another value.

I am using Director for all the configuration of my Hosts and Services, I create a Service template that inherits the default-service template. And that works, until i change the vars.prefix value.

  • Director version: 1.8.1
  • Icinga Web 2 version and modules: 2.9.5
  • Icinga 2 version: r2.13.2-1
  • Operating System and version: Ubuntu 20.04.3 LTS
  • Webserver, PHP versions: 7.4.3

Hi @vegasayoub

maybe it is because of the order of your imports? Example:

template Service "default-service-prefix" {
        display_name = vars.prefix + "-" + name
}
template Service "custom-service-prefix" {
        vars.prefix = "custom"
}

apply Service "test-prefix-service-1" {
        check_command = "dummy"
        import "default-service-prefix" // default template at first
        import "custom-service-prefix"
        assign where host.name
}
apply Service "test-prefix-service-2" {
        check_command = "dummy"
        import "custom-service-prefix" // custom template at first
        import "default-service-prefix"
        assign where host.name
}

Result:
image

Kind regards